Hacker News new | ask | show | jobs
by pconner 3460 days ago
> FORTRAN’s conflation of functions (an algebraic concept) and subroutines (a programming construct) persists to this day in nearly every piece of software, and causes no end of problems

I'm not really sure what the author's point is here. I think "subroutine" is a more descriptive name than the more commonly-used "function," but I'm not aware of any problems this has caused.

2 comments

Functions have properties which are completely defined by their inputs and outputs.

Subroutines (I prefer the term procedure) are just a sequence of commands. They may use arguments and return a value but they can also do anything else.

Functions, real functions, can be reasoned about, composed, mapped over collections, and otherwise trusted to behave themselves. Very few programming languages provide strict functions. One may write them, of course, if one is careful, but that is doing work a compiler could be doing for you.

There's also a disconnect with using a PL's concept of a function (procedure, calling convention) instead of the simple intellectual concept (composition) whether or not you're concerned with the mathematical concept (purity); language compilers or runtimes often perform poorly because as a matter of course every function call adds to a stack (failing to perform obvious inline or tail call optimizations), involves a dispatch that might be more expensive than the function itself (just in case inheriting code overloaded it or because every procedure lives in a run-time mutable table), or causes potentially large copies of arguments (to pretend at them being immutable by called code), etc. -- paying costs which in many cases could be avoided.
Functions can be memoized, procedures cannot. This means that you cannot use anything from mathematical logic for compiler optimizations or program checking/linting or verification. It basically means that you go from at least the possibility of proving something about your operating system/compiler/distributed system correct to it being impossible to prove the most trivial things.