Sunday, January 28, 2007

Functional vs OO languages

Passing judgement on this kind of thing is a bit out of my scope, but I was wound up enough by one of the invited talks at POPL to put my opinion to paper (as it were). First of all, there are a few issues, first is imperative vs functional (ie state-less) programming and the other is abstraction using objects (usually classes) vs abstraction using functions (and, in particular, higher order functions). As the two are usually lumped together so will I, as I'm not so much expressing an opinion as expressing my disgust at other peoples'.

So, I have a problem with the "functional languages are better" opinion that seems to be going around a large part of the programming languages community at the moment. First off, we are all engineers to some degree and should realise there is no such thing as 'better' and especially not 'best'. Functional may be better sometimes and imperative at others. Secondly, I know functional languages are easier to reason about for theorists, easy to optimise, easier to parallelise and generally easier to work with (for theorists); BUT, that doesn't mean they are better for programmers (they might be, but there is no logical implication here). Third: there was a big theme at POPL this year to listen to the software engineers, which is for sure a good idea; however, most software engineers want OO languages, not functional ones, because they believe they scale better to large projects. Maybe they are wrong, but it seems odd to want to listen to them, but then ignore this rather large point. Lastly, my personal opinion is that the better language in a given situation is the one that better matches the underlying physical situation. For things like image processing this may well be a functional model. However, we live in a stateful world and most things in it have state (including programmer's brains), it therefore seems like avoinding state in many programming situations increases the mismatch between the physical and abstract models and thus makes the programs harder to write and understand.

On a side note, Chet Murphy's talk at POPL inspired this overlong rant, and it was kind of inspiring; he certainly had good results and it was a novel and practical use for more hi-tec languages. BUT, it wound me up for a few reasons: it had a hint of preaching to the choir about it; I didn't like the blanket statement (unbacked up) that functional languages are better (which set off the above rant); I didn't agree that functional interefaces to a module imply that the module can naturally be written better in a functional way (there may be internal state that is hard to get rid of, further more at the largest level of abstraction, everything has a functional interface, but not all programs can be happily rewritten in a functional language); the result seemed to be that a mess of a program in one language ran like a dog, when rewritten nicely in another language it ran much faster. This seems to miss the point that the rewriting itself (no matter which language was used) would probably result in improved efficency. Basically, a lot of what he said may be both true and impressive, but the implications he drew didn't seem to be warranted.

No comments: