Lighting the tunnErl Pt 4 – Erlang from a OOPerJanuary 6, 2009
Well this is a little deviation from the previous posts but I’ve ponder writing this post and held back until going back and working with PHP for the first time in a number of weeks.
I’ll focus purely on the productivity of Erlang vs C clones purely from an observation stand point and will leave code comparisons for another blog.
To be honest from my perspective people are as productive as the knowledge and tools they have at their disposal (tried coding a web site in assembly or with buttons?). Initially learning any language or paradigm can appear to slow things down, I feel this is down to the fact the time is need to understand the basics (things that you already know how to do with other tools). At the same time if one is observant of the things that slow them down and work on improving their skills (or addopt new ones) in that area, they soon find their selves just as efficient in those area (sometimes more) as those areas you are traditionally more productive in.
I picked up the language a while after learning and not liking Perl for a web language (for the same reason you dont usea fork to eat soup). I’d been coding C/C++ for a while years prior so the transition was not an issue at all. Initially there wasn’t any decent libraries out there so I had to build things myself. Now 6/7 years later we have frameworks coming out the wood works and all I have to do really is do a little molding, today was a perfect example, being bored I remember I needed a exception handler. The mailer had already been built & for the logging I simple extended Zend_Log, after an 20 mins I had a basic exception handler and was off to the next task.
Now saying this I’m pro TDD and use tools to improve the way I work within PHP, as with most I use frameworks, test units & read a crap load, so naturally that helps.
It has been said that Erlang lacks the tools to compete against PHP/Ruby & the such like, it certainly has a path to walk but saying that it definitely has some decent tools & frameworks around as I’ve highlighted in past posts, which path the way for Erlang taking over some tasks we use PHP & Ruby for these days. There are already a few decent projects out there for the erlanger yaws, mochiweb, beepbeep, erlyweb, etap, not to forget faxien & sinan.
On the other side of the coin, most OOPers wont like the language and I’ve heard/read a few comment on how the syntax makes them feel uneasy, admittedly when I reflect back to the first time I saw Erlang syntax it threw me for six but honestly I thrive on change and quickly found myself wanting to know how the language worked.
Once delving in it was a trial of swings and round abouts, if it wasn’t down to the fact that I practically sleep with ‘Programming Erlang‘ & watch ‘Erlang in Practice‘ I would of given up past Erlang’s docs title page. The resources in my post helped me no bound, along with my stubborness to work things out I don’t think I would of held out to get my head around it. Oh and I forgot to mention, if you don’t know about faxien, then 9/10 one has to resign to compile source, which is all when and good up until upgrade or removal time :/.
Well like i’ve said before I am no way near as proficient in Erlang as with PHP/C and its clones, simply down to the amount of time I have spent using it (4 months study, 3 1/2 practical). Having said that, there are a few things I have observed.
Things that were hard to do in C or PHP (created/manage multiple tasks) are pretty damn easy in Erlang implement a web server, 2mins… can’t do better than that in any other language I know, not even with apt-get. Saying that it works both ways, creating test cases/suites is not well documented leading to not testing and generally hacking, which is pretty crap in my eyes & the analyse tools could be abit more friendly (I’m still trying to get my head ronud dialyze).
The documentation for Erlang isn’t the best (I’ve yet to find decent TDD examples out in the wild on on Erlang & edocs takes some getting used to). Though the community is filling the void with alot of examples and articles, not to forget the community based sites (TrapExit, PlanetErlang, etc). The modules could be more concise and could be organised better but hell, I’ve seen all this before in PHP (remember pre OOP?) & C, they started of patchy and then become stronger as the community recognised them and bridge those gapst.
Erlang makes communication between nodes childs play, as I’ve mentioned in previous posts, a lot of my stumbling blocks with erl come down to over complicating things (an OOP trait). I think once I have gotten out of that habit with Erlang then my productivity increase that bit more. Spawning processes are made as simple as it could ever be & interacting with processes are just the same once you get over the pitfalls (from stores the pid & its ref, forgetting to catch a message, etc).
Things like creating servers is childs play also, making it easy to not only create a number of daemons but hotswap them as and when you feel.
Tools of the trade
Now I’m a firm believer in using the right tool for the right job (just because you just got a shiney new hammer, dont mean you would paint windows with it), the main reason I took up Erlang was because it seems like the right tool for scaleable, system & reliable systems.
Erlang does an excellent job and connecting with numerous nodes and spawning processes to deals with pieces of work. PHP does and goes a good job and helping to create dynamic websites (though to be honest this is a quickly changing trend) Ruby seems to be the bread winner at the moment whilst PHP tries to play catch up. C/C++ do except jobs of allowing us to work closely with assembly code & easily add assembly directly to its sources. Saying this it can take a good few days to get a C application to work ok with threading (barring all the checks & locks) not to mention the time taken to do the real work.
The one thing I love about Erlang is that it hasn’t shunned off the rest of the languages and makes it quite easy to manipulate data even if its at binary level (Joe Armstrongs Icecast example being and shining display of manipulating ID3 tags without the use of external libraries & the such like).
From my current perspective Erlang is excellent for prototyping systems and for creating those reliable highly configurable backend system, we all dream about, that said, it doesnt mean that you should use it for any & everything, sure tinker with it & having a play with the possiblity but hell taking Erlang on board and disregarding the rest would just be plan silly (imo its just something else to add to the mix). I generally don’t pick up things unless it has a practical use, interests me or I enjoy working with it. At the moment Erlang is all of that but Im still not going to push it on all my new projects.
In the last week or two I have become real comfortable with Erlang and have been working on another chat-engine (Chatterl) more and more, I’ve done a few in other languages mainly PHP & Perl, so once I have some of the functionality reflected in my older versions, I’ll dig out the most recent & do some code comparisons. For now I invite you to check out Chatterl’s source over the coming weeks I’ll be focusing on the web interface so I should be able to make some comparisons that that area also.
I’ll say this though, it took a day to whip up the base of my PHP chat system, with basic chat functionality. It took me a few more days to do the same with Erlang and create a system that can spawn groups & users over a number of nodes & shut down them nicely. Doing something like that with pure PHP is just not possible & in C++ a pain in the ass.