Wednesday, February 06, 2013

Haskell vs Erlang

I've been doing copious amount of Haskell and Erlang at work for the past few months. I can't say that I'm an expert at either (in particular, Haskell continues to fascinate and frustrate me), but I have solid software that is about ready. (Laptop monitoring software that must work silently and safely 24x7.)

Most of my prototype was done in Haskell and I rewrote some of the software in Erlang.  There were pluses and minuses for both languages.

Take, for example, some applications I had to write to interface with D-Bus (pretty much the standard for Linux process to process communication these days).  I couldn't find a D-Bus interface in Erlang, but the Haskell one was pretty comprehensive.  It was a bit of a struggle, but the payoff was that when I  finally got the code to compile, it pretty much ran flawlessly. Haskell is pretty strict about data types and D-Bus is all about moving data structures around. There was no "ball of mud' structure could trip me up later, I had to explicitly describe the data structures in completion.  Once the D-Bus code compiled, it worked.

Three months later and that Haskell D-Bus code just purrs along.

But, then there was BSON.  I had to produce and consume some structured binary data. I considered using Google's Protocol Buffers, but that was too rigid. I was still working out fields that would comprise the data and didn't want remote stuff to just stop working because I tacked on an extra field.

Here, Haskell was a struggle. You just don't toss around arbitrary data. I was getting runtime failures whenever an errant structure element appeared. Yes, I know, I should be handling the exceptions, but this was proof of principle code and I had yet to harden it. Bad me.

Erlang, meanwhile, shined where it usually does: When I wanted a failure recovery strategies and tons of crash diagnostics, it produced them.  Plus, Erlang OTP is a lot like Unix: It is a complete runtime environment (log rolling, process management, etc).

Both languages were a pleasure to use. Haskell was a pleasure to compose apps with and Erlang was a pleasure to orchestrate a system of communicating processes.  They both have their places.  I can't see replacing any of the D-Bus interfacing apps (currently in Haskell) with Erlang, yet Erlang  OTP certainly rocks with its ability to stay up and running.

No comments:

Post a Comment