Computational divertissements

Pure functions and three sided triangles

Posted on

In recent years functional programming has become if not trendy then at least less niche. Well-meaning introductory articles often bring up the idea of 'pure functions'. The qualifier 'pure' suggests that pure functions are to be singled out in contrast to some other sort of function. What is it that sets pure functions apart? The answer varies across authors, but it tends to be something along these lines:

These are all very nice, but there is no need for the 'pure' qualifier. Anything purporting to be a function but lacking these properties is just not a function. One could call such a thing a subroutine, a procedure, a method, a code blob, whatever. The word function already has a well established mathematical meaning that covers these purity concerns. It has been in use since Liebniz introduced it in 1673. The idea of a function has been around even longer.

To speak of 'pure' functions makes as much sense as speaking of 'three-sided' triangles or 'aqueous' water. There is no other kind. The fact that various programming languages misappropriate the word is unfortunate. I prefer the established mathematical usage.