[erlang-questions] OO programming style in Erlang?
Tue Jan 23 20:11:51 CET 2007
Sean Hinde wrote:
> On 23 Jan 2007, at 17:30, Ladislav Lenart wrote:
>> Sean Hinde wrote:
>>> A certian Lisp/Smalltalk hacker round these parts keeps telling me that
>>> Smalltalk is something like Erlang in concept, but I never quite
>>> listened hard enough to see why ;-)
>> But from a point of view of an experienced Smalltalker,
>> I must say that the shift from Smalltalk to Erlang is not
>> so trivial, mainly because of a quite complex and fixed
>> syntax. I got quite used to the idea of minimal language
>> syntax and extendable libraries over the years. And this
>> I miss a lot in Erlang. A simple example to illustrate my
>> point follows (maybe you will even tell me a simple way
>> how to do something like this in Erlang?)...
> And now you are at it as well !
>> Let's suppose I have to write a lot of code like this
>> in Smalltalk:
>> anObject isNil
>> ifFalse: [anObject doSomething].
> Well, fairly meaningless so far.
> One comment - Erlang is not about sending messages as some kind of
> alternative to calling a method. Code that implements the business logic
> is normally written as a bunch of pure functions that take data
> structures as inputs and return manipulated data structures. No side
> effects or external state change in sight. String a bunch of these
> together and you have as complex a logic as you want.
> Data structures are by nature highly symbolic (the atom type) and (apart
> from dedicated ADTs like dict and gb_trees) tend to be complex, exposed
> and passed around and operated on directly by pure functions.
And this I guess is the part I have a psychological problem with.
I am used to an idiom where data are hidden behind an interface
that operates on them. This decouples user of the module from
having to deal with internals of that module. But as you described
it, data are exposed in Erlang. So each time you want to change the
representation (add something because of one new function), you have
to revisit many of the existing functions that operate on that
representation. This seems more than a few changes to me...
More information about the erlang-questions