What I Did on My Winter Vacation

I recently took a position at a new company. This was a big deal for me since I’d only changed jobs a couple of times before. A good chunk of the last job was spent amassing institutional knowledge and (I hoped) maturing as a programmer. I was always dubious on the latter. The new job was exciting because I knew I’d be working in a new language, and there was a good chance it’d be Erlang.

I have virtually no work experience with functional languages. Despite that, I find them fascinating and have spent hundreds of hours toying around with various Lisp mutants and Haskell

Those languages have always seem vastly removed from the kind of professional work I’ve done, which is hacking on small to medium sized servers written in C and C++. In every language I’ve used, there’s been a tacit acknowledgment that concurrent programming was hopelessly fucked up. Even though you really need it (or maybe you just think you do) you probably shouldn’t use it unless you’re insane, and even then all you have to look forward to is an undebuggable nightmare of code that may or may not actually do more than one thing at a time anyway.

I didn’t really understand how Erlang’s functional nature contributed the abilities that I found mind-blowing- its hot code swapping and concurrency abilities. I don’t think it was ever really that bad with threads in C/C++, but the idea of concurrency being a mundane topic in a language is kind of exciting.

If it isn’t already obvious, I’m not a computer scientist, and I’m not ashamed about it. Interviewers who elect to grill me on theory-of-computation stuff will be disappointed. I understand most of the stuff but I don’t find the theoretical parts of computer science very interesting until I encounter in them real world problems; then I can’t stop thinking about them.

Erlang was therefore a perfect conundrum for me- a language that lets me run reliable concurrent programs that don’t need restarting when deployed? Hey now. An extensive networking library, runs on switching equipment? I’m getting a tiny digital erection. The only problem is that my Lisp abilities rival those of a four-year-old, I’m terrible at programming with recursion, and I’m barely able to understand my Xmonad .hs file after years of hacking on it.

One thing I’m certain of in life is that it is difficult to predict what you’ll be able to learn. Some things seem like they couldn’t be that hard but I’ve found absolutely fucking possible, namely, Ice Skating. Some time I’ll write a post about that.

Some other things seemed nightmarishly difficult to me, like driving a stick shift, or learning to corner a motorcycle correctly, but they turn out to be pretty easy once somebody tells you how to think about them, especially if somebody pays you for doing it 40 hours a week. Immersion and repetition are the keys, and that’s why I believe the most effective way to learn any programming language is to volunteer yourself when there are opportunities to get thrown into working on somebody else’s code in a language you don’t know, trying to find the right spot to slot-in the stuff you’re tasked with adding. The very best situation is when the existing code doesn’t suck; the code itself becomes a conversation partner who doesn’t talk too fast or use too many vapid colloquialisms.

Anyway, my honest expectation was that I was going to totally blow at Erlang, in the way I usually totally blow at Project Euler problems that people can solve in three bytes of Haskell but take me many hundreds of lines of C or Go. If I can solve them at all. I pictured myself becoming embittered from struggling with this purist, elitist functional bullshit with it’s stupid variables that can’t be reassigned, tearing out my hair and thinking all the while about how I wish I had my stupid templates and the STL back, all the while fantasizing about serially murdering mathematicians in a rage over my shortcomings as a functionista.

It turns out that I needn’t have worried. There are of course loads of annoying jackasses bloviating about how you should abandon everything, eat only brown rice, and read their latest blog entry about how in actuality there is only one program in the universe, a gigantic 13-dimensional Haskell monad that they have just released on github. But it’s just like when Java came out, only now you don’t need a publisher.

Contrary to my doubts, the switch to Erlang has been exciting and refreshing. Some of patterns that I’d seen growing in frequency in my programming– the near compulsive use of maps and filters, a growing disdain for incomprehensible class megaliths where some tuples would do –turn out to be the ordinary way to do stuff in Erlang. Instead of trying to figure out how to make code look good, I’ve spent most of mine time tearing problems into little pieces because it’s the only way I can figure out how to structure the program. I found I wind up writing code that is concise and readable just because it would be more work not to.

However, I think that it would have been impossible for me to have written a program in Erlang from scratch, at least not one I’d have been happy about. I was fortunate to be doing maintenance on an existing program of a good size and quality and of greater complexity than some dorky TODO-list application from a book. Surprisingly little reading was required, and the excellent Emacs erlang-mode has been a powerful tutor by refusing to indent things for me until I got my semicolons, commas, and periods in the right spots.

The main thing I like about Erlang though is that it is clearly an industrial tool; although writing a factorial function has replaced “Hello World” in Functional Programming books, Erlang is the only language I’ve seen where they have you writing a factorial socket server instead. The library reminds me of Go’s; heavy on the bit-pushing stuff and with documentation that looks like something that would have come in a crate of gray three-ring binders with a part number and a dizzying price. This thing may be modern but it’s not just some research project.

Anyway the point of this site is to offer whatever assurances I can, via blogging, that there is plenty of room in the world for us non-hipster programmers. So for what it’s worth, I think it’s safe for me to bestow the GO=C800:5 Seal of Approval on Erlang and some of the tools I’ve been working with, like Basho’s ass-kicking webmachine. If you’re coming from a procedural background like me but you don’t fancy get mired in a bunch of esoteric crap, don’t pass up an opportunity to hack on some Erlang.