Better living through immutability or What have functional programmers ever done for us?

For more than thirty years, alongside conventional language development, there’s been a small but thriving culture of functional languages.  These are not like the languages we all know and love.  Their most obvious property is that they contain no variables at all; instead, they describe truths about the problem to be solved[1].

As anyone with even a passing familiarity with functional programming knows (and I accept that passing familiarity usually comes only after three to five years), things in a functional language don’t do anything (the way procedures execute or variables change in conventional languages); instead they are something, and what they are never changes.  A term may describe a function which defines a list of primes, or it may describe what it means to be an expression, or what-have-you.  But whatever it is, it describes it once and for all time – the function is the list of primes, it’s not a sequence of operations to compute the list.

Proponents of functional languages claim that by talking exclusively in terms of values, you get shorter, simpler, and more reliable programs.  If things are things, rather than do things, they reason, then if they ever work, they’ll always work.  If nothing ever changes, where can a bug hide?

Continue reading

If statements considered harmful or Goto’s evil twin or How to achieve coding happiness using null objects.

When Edsger Dijkstra wrote his famous letter to the ACM in 1968[1], he created two things which we now take for granted: he condemned, in entirely theoretical argument and for all time, the goto operation; and he introduced the “considered harmful” tag.  Two out of three ain’t bad.

Continue reading

Exceptions Considered Harmful or: throw is just goto in drag

The two pillars of modern software design are objects and exceptions. Objects allow us to partition very large systems into smaller, comprehensible chunks, and exceptions keep them running smoothly, by protecting them against malfunctions.

Funny thing is: though modern software is huge in comparison to the old-fashioned variety, it doesn’t seem any more reliable. Even though everybody knows that exceptions make programs better, I’ve never yet seen any real evidence that shows any reason even to suspect that it’s true. In point of fact, I don’t believe it, and I rather suspect that in most cases, exceptions make matters worse. Continue reading