[erlang-questions] is there "return" in Erlang.

Ulf Wiger <>
Mon Feb 28 15:46:07 CET 2011


On 28 Feb 2011, at 14:15, Jesper Louis Andersen wrote:

> The problem here is that doSomeThing(a); is done for its side-effect
> only. The only possible side-effect in Erlang is that it communicates
> with other processes

Well, there are other ways - all of which could be modelled using processes,
but in fact aren't (updating ets tables or the process dictionary, for example),
but I agree with your point, and want to emphasise it.

One thing that will grow in importance as you learn to appreciate the differences
between pure and impure code, is that code like this - which can *only* be useful
through side-effects - has a toxic effect on your code structure.

Even if functions depend on side effects for their operation, it is a very good idea
to design the calling structure as if they didn't.

Act as if you were pure, and… well, purity won't be given to you, but at least you can convert later.

A good example is the ets API. Kresten used Clojure's persistent collections to implement
ets tables in the JVM, but whereas persistent collections are immutable by design, ets
tables have an imperative API that makes it impossible for them to inherit some of the really 
cool features of persistent collections. In the old days of single-core machines, ets tables 
were used a lot for performance. On SMP machines, they turn out to be among the hardest
parts of erlang to make scalable. This is in no small part due to the fact that the API enforces
a shared-memory mindset.

BR,
Ulf

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com





More information about the erlang-questions mailing list