inicio mail me! sindicaci;ón

Erlang and the GUIs

Erlang is great about concurrency, fault-tolerance and performance but what about the old simple GUI support?

I made a quick research and I came up with this:

  • Gtk (my favorite toolkit) is available in two libraries: erlgtk is the first hit in Google but I didn’t manage to compile it in OSX so I dropped it down. The project is also discontinued so nothing to see here sadly :-( jungerl is a collection of very interesting stuff for Erlang and beneath it there’s gtkNode which wraps GTK 2.8, supports Glade and seems really promising although it’s not updated since months… Anyway it seems to work well but it requires X11 under OSX so a bit unhandy.

  • OSX Aqua: I haven’t found anything…

  • Qt: I haven’t found anything…

  • Tk: Erlang ships with GS which stands for Graphics System, a portable library indipendent from the underlying graphic system. Here uses Tcl/Tk and seems simple and cool.

For now that’s all. I’m going to use GS for my experiments but it’s nice too see that there’s some support for Gtk too!

I’ll update this post if I found out more.

Update (2006/09/20)

Liam Clarke mentioned wxErlang and I forgot to add EX11 in the list so here are two more:

  • X Window: EX11 is a X Window toolkit written in 100% Erlang that talks directly to the X Server, so its power is quite unlimited. The latest version is 2.5 released in 2004. My opinion is that screenshots look kinda ugly and it’s a bit low level (…since it talks with the X System directly). Anyway the simplest tutorial example didn’t work for me so I can’t say more. Joe Armstrong published a series of slides about EX11 if you want to know more: EX11 - An Erlang GUI.

  • wxWidgets: wx has the ability to use other toolkits for rendering so they (at least in theory) render equally your favorites native apps. wxErlang is a prototype implementation but it definitely looks nice on OSX. The project seems halted though (the latest CVS commit is from 10 months ago). Once more time: this library didn’t even compile on my machine so that’s all.

After digging into these two additional libraries I think I’ll stick with GS and gtkNode for my experiments.

Erlang is damn intuitive

Erlang is a multi-paradigm language since it has functional, declarative and imperative functionalities. Erlang exploits concurrency in a wonderful way through an asynchronous message-passing model. Erlang’s processes are lightweight (about 300 byte each) and the overall architecture is very fast.

I’m learning Erlang for fun and yesterday I tried to implement the simplest master/slave architecture: a master with N slaves linked to it; when the slave dies the master gets notified and regenerate it.

Sounds quite complicated in… Java but in Erlang takes 50 lines of code.

The key to the heaven lies in link/1 used to create a bond between two processes. When a processes dies Erlang automatically notifies the master with a failure message. The master has to trap those kind of messages with processflag/2 and handle them in the receive block.

Does the module sound simple? It is simple.

master slave

Toying with Erlang

There’s plenty of messages in the blogosphere about Erlang these days so I’m not gonna make praises for this wonderful tool some more. If you’re interested in concurrency and you had enough with the thread jiggling go check it out and learn message passing with Erlang.

After reading here and there I tried to write a simple pet program dealing with concurrency and I came with a very simple star topology example. You create a bunch of processes and send a message back and forth to them until the counter reaches 0. Nothing can be more simple in the message passing world! You share nothing, you create lightweight processes and you come up with something like this:

Read the rest of this entry »