I often think of why I feel that it’s important to have a functional language—not just write code that’s pseudo-functional in an imperative language. As I think this through, I wanted to record some of my ideas on the subject.
Even the best developers I’ve known are almost always inclined to take the defaults. I mean if the default string type is ASCII then you’re very unlikely to see Unicode strings in the app unless someone specifies that this is needed. This is not laziness; it’s simply that these developers have other issues to concentrate upon.
Why is this important? Simply this: I’ve come to realize that default mutability is an accidental complexity–in the sense that Fred Brooks used that term in his “No Silver Bullet” essay. Don’t misunderstand what I’m saying–mutability is necessary and appropriate. But having all values in software mutable by default is an invitation to lots of unexpected side effects. And this is why I really believe that functional languages will continue to gain in use. Functional languages are immutable by default. Impure functional languages (OCaml, F#, Clojure, and Scala among others) do allow a programmer to specify mutable quantities where it’s appropriate due to performance considerations but they default to quantities being immutable–and that’s why they’re important. If things default to being immutable, developers will learn to work with immutable quantities and become accustomed to them in the same way they’re now accustomed to thinking in Objects. People seem to forget that 30 years ago, OO was as much an academic discipline as Functional is now.
Every developer knows they should mark quantities as constant (or final or readonly or whichever keyword expresses immutability) but most do this only as an afterthought and they do it incompletely. Default immutability could eliminate a whole class of side-effect errors and therefore reduce errors in our code by a large fraction of all errors present. The issue is not the question of does “const correctness” (for lack of a better way of phrasing it) make software less error-prone; the issue is getting developers who are always under impossible deadlines to use constants by default. Languages that default to constant, immutable quantities are a large step in that direction. This is why functional programming is important and this is why you’re going to inevitably see more and more developers gravitating toward these functional languages.