I'm a software architect/consultant in Boulder, Colorado. I started blogging at: http://wayne-adams.blogspot.com/, but have since started the new blog, Data Sceintist in Training which will cover the areas I am learning as part of my own "big data" training, including the Hadoop family, frameworks like OpenStack, the R programming language, column-oriented databases and the art of examining data sets for useful patterns. The original blog will be kept alive with Java-specific posts. Wayne is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

Day 5 - Erlang

04.04.2011
| 3700 views |
  • submit to reddit

If you are just dropping in on me, I'm reviewing Bruce Tate's Seven Languages in Seven Weeks, with the slightly lazy (or aggressive, depending on your view) twist of reviewing one language per day. As you can imagine, shrinking an already-tight one-week study schedule to one day means glossing over some things and skipping the extra exercises. The idea, though, is to still get a good feel for the topography of the language, and as I've already pointed out, this is a great little book and will be my first contact for the languages I choose to get to know a little better.

The 5th language of this book is Erlang ("Ericsson Language"), first developed by Joe Armstrong in 1986. A functional, dynamically-typed language geared toward telecommunications and its high availability requirements, Erlang relies on lightweight processes (rather than threads) as its base model. It is based on and quite similar to Prolog, something brought out by Bruce's interview with Joe Armstrong. Have I said I really like the interview portions of this book? After enough years in this industry, I had started to say "one more language; let me take a look at it and just give me the API docs", but after reviewing these languages I see I've overlooked the huge amount of variety in the development-language world.

Erlang is a compiled language, but it provides an interpreter which Bruce uses for the earliest, shortest examples. In his Day 1, Bruce discusses atoms, variables, lists and tuples, and gives a short discussion of pattern matching (including bit matching). Day 2 starts by discussing control structures, mostly case statements but also including the if statement.

Bruce then moves on to higher-order functions, starting with anonymous functions, and discusses using functions to manage lists. Highlights include the foldl and foldr functions, as well as a brief review of Erlang's list comprehension.

On Day 3 (using Bruce's timeline), he talks about concurrency. I said earlier that Erlang looked more to lightweight process than lightweight threads as a base model. The concurrency primitives in Erlang are sending messages, spawning processes, and receiving messages. He covers pattern matching in receive loops, which have a syntax similar to case statements, then discusses the use of spawn to spawn a process. Finally, the returned process ID of the spawned process is used as the destination for messages. He walks us through an asynchronous example, followed by a simple asynchronous messaging example. He then discusses linking processes and how to handle death (exit) of a process by its linked process (a technique used to create monitoring and keep-alive services).

The end of the Erlang section covers strengths and weaknesses of the language. One weakness, if you can call it that (at least from an adoption point of view) is not being on the Java Virtual Machine. I thought of this frequently while going through the Erlang section of this book. Reading about Erlang's support for concurrency is refreshing and quite inspiring for me. However, I know that I will most likely eventually use Scala. Why? That JVM is just going to make it a lot easier to sell to management. That might be a shame, but it's kind of a fact of life. I remember really liking Smalltalk, but realizing that summer was coming to an end and going with C++ anyway. But it doesn't mean I don't still think fondly of my first Smalltalk application. :) 

From http://wayne-adams.blogspot.com/2011/04/day-5-erlang.html

Published at DZone with permission of Wayne Adams, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Arek Stryjski replied on Mon, 2011/04/04 - 4:40am

There is a projects to port Erlang into JVM https://github.com/trifork/erjang/wiki/ I don't think it is production ready, but maybe it is worth to mention it.

Damien Lepage replied on Mon, 2011/04/04 - 9:10am

Thanks for this interesting series. Your posts give us an even lazier approach, closer to 7 languages in 30 minutes. Considering your last paragraph I'll be interested to see if your choice is still Scala over Clojure after tomorrow.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.