Tuesday, November 17, 2015

The right tool for the job

Had a fun debate in Languages class this evening revolving around the undeniable fact that functional languages don't get a whole lot of use. The advocates of such languages seem convinced that this is recalcitrance on the part of the programming establishment further impaired by the fact that the underlying hardware is biased towards imperative statements (computer engineers are apparently in on the conspiracy).

I generally keep an arms distance from debates involving zealots but, since nobody was taking the pragmatic side, I decided to call shenanigans.

Lets start with the easiest part to debunk: hardware has nothing to do with it. C++, Java, and C# would never have supplanted C if fast execution was the primary concern of developers. Scripting languages are an order of magnitude slower than LISP, yet mountains of code are written in them. The truth is, with a few exceptions in the areas of systems programming and real-time apps, nobody cares about performance anymore. Just use Facebook on an iPhone4 over 3G if you don't believe me (I do this all the time, and it's sloooooooow). Users who want snappy performance are happy to pay for it by purchasing better hardware.

So that leaves us with the great mass of anti-functional programmers. Are these folks just not good at math? Do they not see the value of referential transparency? Do they not see the evil in side effects?

Whoops, ya might be onto something with that last one. I just called a function that wrote a record to a database. That's a side effect. BAD! I just wrote another that sent a message to a web service. Side effect, BAD! This one turns on your cell phone camera. Here's one that changes the thermostat setting in your house. Another alters the fuel mix in your car's intake. BAD BAD BAD!

The truth is, the vast majority of what computers actually do is side effects. Performing actual computation is maybe 5% of computing. The rest of it is just moving crap around and interacting with peripherals. Functional languages are terrible at this because THEY DON'T ALLOW SIDE EFFECTS.

I'm all for using functional languages for what they are good at: computing functions. But if I want a computer to actually do something, I tell it what to do. Which is, of course, exactly why they are called imperative languages.

No comments:

Post a Comment