[erlang-questions] If you are homesick for object.selector

Fred Hebert <>
Fri Jan 25 19:26:52 CET 2013

On 01/25, Garrett Smith wrote:
> Let's compare this:
>   Strength = '?'(Char, [stats,skills,strength])}
> to this:
>   Strength = Char.stats.skills.strength
> Now, which would a beginner prefer? The first version is *terrifying*.
> And if the programmer *could* brave the syntax, what about all that
> extra typing?? Just looking at that code makes my fingers tired :(
> That's why Ruby is #2 on github language ranks and Erlang isn't even
> in the top 10! [1]

Of course it's terrible. It's a 15 minutes attempt to show it's doable
to navigate deeply nested data structures. I might as realistically make
a function that accepts:

Char = set(new, stats,skills,strength, 50)
Strength = get(Char, stats,skills,strength)

by using parse transforms (you can get list of args and redistribute
them the way you want, iirc), using my module from the previous e-mail as
the underlying representation. This can be done as a blind replacement,
without any new support from the language, with currently existing
tools, and work on pretty much any reasonable depth. Someone just has to
go through the trouble of doing it. Plus you could automatically change
representations by having different parse transforms. One for tuple
lists, one for dicts, one for ETS, whatever you feel like.

These two versions are not significantly annoying -- they don't even
need annotations for types or pointers or whatever the way many
languages would need them. Clearly they would be concise enough.

There are reasons for Erlang to not be that used, but accessors for deep
data structures are likely not the most important part of it. I'd
probably bet on the difficulty to translate algorithms that assume O(1)
access to hashes or arrays, with destructive updates, as a significant
barrier of entries with far fewer easy workarounds.

That's all speculation anyway.


More information about the erlang-questions mailing list