We had a meeting on Tueesday evening to discuss our first impressions on Erlang. We have all been using the book ‘Programming Erlang’ by Joe Armstrong. We were a little late getting started but Steven, Andy, Graham, David and myself eventually found eachother.
None of us had used Erlang previously but Graham has used Haskell a lot and noted some of the major differences between the them. I should have started taking notes earlier but the two that stood out for me were that Haskell has lazy evaluation and strong typing.
The biggest interest in Erlang was its scalability thanks to concurrent and distributed applications being easy to write. We did wonder how Erlang might balance load in a distributed environment and quickly came up with a wish list – can Erlang choose how to distribute load across nodes, and can it migrate a process to a different node? I’m sure with use these questions can be answered.
Everyone seemed to agree that the language feels quite old. My memory about it appearing in its current form around 1990 was correct but most people thought it must have been older. Its apparent age probably comes from how it appears to a newcomer when seeing things like make files and lack of UTF8 support at the heart of the language. Steven mentioned that he also thought some common programming tasks seemed to look awkward – I think his example concerned lots of calls to lists:reverse. Graham suggested that when more familiar with functional programming such scenarios may become less frequent as things can be done differently.
We also discussed the book. David asked if we thought it would make a good reference for beginners. I thought the examples were very good and some of the later programs appear to achieve a lot in just a couple of pages. On the downside, there was more than one occasion we were unable to find a topic we were discussing in the index.
For myself, there was a lot to take in. I enjoyed reading the book but started to forget some of the syntax as I read more complicated examples. The book does suggest actually trying the examples while working through the book so maybe I will start again. Graham and David thought that it is unlike a lot other books on functional programming due to its focus on practical programming and not so much the theory.
I believe that only Chris has so far tried something in Erlang but since he wasn’t present we all concluded this might be a good next step
Thanks for writing up some notes Tom! It seems like I’m the only person who has been doing any programming in Erlang. In fact I’ve made a point of doing what Tom mentioned, which is to actually try out some examples as I’ve gone through.
I agree with much of what was said. I’m completely new to functional programming so it has been interesting to look at coding from this novel angle. I’ve found it a little hard at times to shake off my imperative coding habits.
So I have followed the examples and tried the exercises. One piece of code that just looked wrong to me was the find_sync routine on p85. This looks for three consecutive MPEG headers in the data. The issue I had with this is that it is basically the same piece of code embedded within itself three times. Not what I would call elegant! I was forced to rewrite this just for my own piece of mind. I added it to the example code and called it find_sync2. You can find it here:
http://oxtremists.co.uk/svn/erlang/mp3_sync.erl
any comments on this code would be readily accepted. I did test it on a real mp3 file and it seemed to do the same as the original.
Something else I started was a sudoku solver program. The main problem I hit with this was in deciding how I should store the data representing a grid. Initially I started out with a list, as that seems to be the standard collection type in use in Erlang. But lists are not really random-access collections. There is no BIF to allow you to replace the Nth item with M for example. I also started noticing that the list processing BIFs that there are seem to be rather inconsistent. So lists:sublist which gives you the first N items in a list takes the argument list (List, N) but lists:nthtail which does the reverse and gives you the items following the first N items takes the argument list (N, List).
So how about tuples? There’s a BIF to replace the Nth element with a different one, but there are very few other BIFs available to do anything else. Finally I found that there is an array module (not mentioned in the book) http://erlang.org/doc/man/array.html should I be using that? Basically, I’m confused. Obviously I could do it using any of these, but I don’t want to go re-inventing any wheels on the way….