Lambda the Ultimate

inactiveTopic Erlang to OTP: A heavy duty TCP/IP Client Server applicati
started 9/25/2001; 5:06:48 AM - last post 10/1/2001; 3:39:20 PM
Ehud Lamm - Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/25/2001; 5:06:48 AM (reads: 1359, responses: 11)
Erlang to OTP: A heavy duty TCP/IP Client Server applicati
(via comp.lang.functional)

Industrial scale FP seems at time an illusive goal. Erlang often comes to the rescue with examples of real life applications, many with real time and embedded components.

This paper too deals with a real application: an instant messaging system supporting 10,000 users, based the Jabber protocol.

The paper is important in that it emphasizes programming-in-the-large issues for Erlang applications, specifically the OTP framework.

Another aspect of the paper is the issue of programmer training and language documentation, esp. as regards languages released as open-source.

Our very own Chris Rathman is mentioned in the paper, which is in itself another good reason to link it in


Posted to functional by Ehud Lamm on 9/25/01; 5:08:34 AM

John Lawter - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/25/2001; 7:17:28 AM (reads: 1376, responses: 0)
One thing that interested me in the article, and that I don't feel was adequately explained, is the following:

"Something more powerful than object orientation?" It sounded too good to be true. ...Object Orientation is not necessarily the best way to design and structure a piece of code. It might appear easier to learn and use, but when applied to larger system, the theory does not work. Users are forced to add "technical" objects that often result in complicated hierarchies. This makes the system architecture complex and sometimes affects the performance of the application.

Since the article brought it up, I wish that they had given an example to illustrate what they meant by "'technical' objects," and why they feel Erlang's "behaviours" provide a better way of structuring code.

Chris Rathman - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/25/2001; 8:01:25 AM (reads: 1372, responses: 1)
Maybe this means that someone in the Erlang community will get around to showing me a better way to do the example. :-)

When I was looking at Erlang, they had the main chapters of the redbook online, but I had to stealthfully read the chapter on OO programming in the local bookstore (didn't want to shell out $60 for a single chapter).

IIRC, the red book shows how to mimic inheritance in the language by using cooperative modules. It was kind of silent though on the question of polymorphism, which is actually (in my opinion) the more important point to OOP. I did figure a way to get polymorphism via messaging based on some of the hints provided. Indeed, at the heart of Smalltalk's OO technique is the message dispatch, and Erlang excels at messaging (i.e. threading).

When I wrote the example the first time, I combined the technique of inheritance and message polymorphism, but I ended up with way too many messages being passed around. The subclass object has to manually pass messages up the inheritance hierarchy to the superclass - something which OO languages do for you automatically. Being a bit too cumbersome and obtuse, I jettisoned the inheritance in favor of simply demonstrating polymorphism and encapsulation.

Thinking back on it, I figure there has to be a better way to pass messages on to a superclass without having to intercept and interpret all the specific messages. Something like a doesNotUnderstand: where the subclass passes all messages it does not understand up to the next level of inheritance.

As for the article, I agree that OO techniques of inheritance and polymorphism are a tad cumbersome in Erlang, and that it would be difficult to scale. OO in Erlang is more akin to being a usage pattern rather than a language design issue. In limited instances, though, it can be useful for constructing solutions. As with the above article and the chapter in the redbook, OO is downplayed as a viable solution in Erlang. As such, it is mentioned but not thoroughly explained.

Ehud Lamm - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/25/2001; 8:22:49 AM (reads: 1438, responses: 0)
I know of at least on Erlang fan reading (and managing) LtU, but do we have any real Erlang hackers around here?

Well, I know we do...

Luke Gorrie - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/29/2001; 6:07:32 AM (reads: 1376, responses: 0)
Basically I think the "OO in Erlang" stuff is mostly arm-waving. It's not really how you write Erlang programs, it's more of an interesting programming exercise. It's talked about as much as it is because it's always the first thing that people coming from an OO language want to know about (I know I did). Really Erlang has it's own wonderful programming style that eventually sinks in.

I guess it's always the same when learning new languages. You try to write programs in a way that you're used to, and then at some point you get an "aha!" moment and go native. I got my "aha" in Erlang when I eventually wrote a genuinely concurrent program (SMTP server).

That's what I recommend - writing a program (or two) that's inherently concurrent, and suddenly it all makes sense :-). Especially programs where not every process is a server in an infinite request loop (basically an Object). It's more interesting when you have processes that are just spawned to do a single task and then terminate (or crash trying), and processes that are state machines, and all that good stuff.

P.S. I'm still baffled at how Erlang programs can be so nice while using almost no polymorphism. I've no idea where it disappeared to, but I don't miss it anymore!

Luke Gorrie - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/29/2001; 8:14:07 AM (reads: 1306, responses: 0)
In reply to the first post, I think that "technical objects" are what you get when your program is object-oriented, but your application essentially isn't. Just like in Erlang you'll sometimes get "technical processes" when your application isn't naturally concurrent.

I would say from personal experience (YMMV) that a GUI is naturally object-oriented but not naturally concurrent, and a webserver is naturally concurrent but not naturally object-oriented. So all other things being equal, you'll write a more natural and beautiful webserver in Erlang, and a more natural and beautiful GUI in an OO language.

(Of course, all other things are anything but equal :-)

A great example of "technical objects" is Doug Lea's util.concurrent [1] package for Java. He's invented a whole lot of rather complex objects for different sorts of synchronization in a concurrent system, which mostly just disappear if you're programming in Erlang. They're not modelling real world objects, they're just the extra work you do to write concurrent programs in a language that wasn't designed for concurrency.

Similarly, Chris's OO in Erlang [2] is a great example of "technical processes", which are not actually modelling real-world concurrent activities, instead they're just the closest thing that Erlang offers to objects and classes - which is not that close.

As they say, "use the right tool for the job."

NB: my favourite personal program is an Emacs clone I'm writing in Erlang. This is not really a naturally concurrent program, and I do have "technical processes" (for buffers) which don't really fit the problem very well. I keep trying to wrestle the structure into something natural and beautiful, but no luck yet!

(Of course, the Lisp guys with their adaptable programming language can laugh at us all - but then they don't seem to be doing anything fun anymore :-))

[1]: http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html [2]: http://www.angelfire.com/tx4/cus/shapes/erlang.html

Ehud Lamm - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/29/2001; 11:13:45 AM (reads: 1325, responses: 0)
Concurrent processes, like objects, have state. In this sense they are quite similar. Concurrent processes, in fact, remember their control information (program counter, continuation, or what have you), on top the state information the have in common with regular objects.

Does the Erlang design specifically address this issue, Erlang being a functional language?

Luke Gorrie - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/29/2001; 3:42:41 PM (reads: 1318, responses: 0)
Processes, particularly servers, do have some things in common with objects. But if you try to use them as objects, you'll deadlock as soon as your call graph cycles :-). For all their similarities they support drastically different programming styles.

I can't speak for the Erlang design, but maybe someone who can will pop in and say a few words.

Chris Rathman - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/29/2001; 10:09:40 PM (reads: 1294, responses: 0)
Does the Erlang design specifically address this issue, Erlang being a functional language?
I gather, from the original article, that they thought the OTP library was the way to go in terms of segregating the Erlang code into larger scale services (processes, etc...).

As for built in language support, I gathered that you can use tail recursive functions from a process dispatcher to get the control information to vary over time (i.e. to get around the write-once variable framework). Of course, you end up bypassing the advantage of referential integrity if you use this pattern, as the value provided by a process becomes time sensitive. Ideally, you want to minimize the dependency between threads in order to maximize concurrency - i.e. you don't want threads waiting on each other and you definitely don't want them stepping on each other.

Instead of using a local variable to hold state information, you can spin off a thread that can hold that information. The value can be set by attaching a value to a message to the thread (via it's pid). The stored value can then be retrieved later by passing another message to the thread and requesting the current value.

The thread message handler recursively calls the function that handles the message handling with the newly received value. If the function is tail recursive, the stack space is not eaten up, and the write-once variables suddenly act as if they can be set any number of times.

Ehud Lamm - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
9/30/2001; 1:28:14 AM (reads: 1291, responses: 0)
if you try to use them as objects, you'll deadlock as soon as your call graph cycles

I'll try to clarify what I meant. I didn't mean that concurrent processes are in general equivalent to objects. I made the much weaker claim that they both have state information.

This may mean that when reasoning about concurrent processes you can't sue the "shortcuts" that make functional languages easier to reason about (i.e., referential transparency).

Luke Gorrie - Re: Erlang to OTP: A heavy duty TCP/IP Client Server applicati  blueArrow
10/1/2001; 3:39:20 PM (reads: 1300, responses: 0)
Erlang's definitely not a purely functional language in the sense of Haskell etc.

I never quite know what people mean by "reasoning about" programs, I guess it means understanding them. I think that Erlang processes make concurrency a lot easier to understand (reason about), especially when you consider the possibility of bugs and failures. Most of the rest of Erlang is purely functional, which I think makes it easier to understand and to test, too.