What’s A Function?

If you’re a mathematician, a function is a sort of transformation, a mapping of a set of values onto another set of values. Each potential input value maps to an output value. I tend think of it as a little machine that turns its input into its output.

If you’re a programmer, a function is a subroutine, a named sequence of instructions. Some code you wrap up in braces and give a name to. You can call it.

It doesn’t feel like a stretch to suggest that the “functional” in “functional programming” refers to the mathematical definition. Functional programmers treat their subroutine-functions like math-functions: purity, no side effects, data-in-data-out.

It might even be useful to stop using the word “function” for procedures/subroutines. This’ll never happen, of course, but it’s an interesting thought. It could make these different concepts clearer.