[erlang-questions] The Beauty of Erlang Syntax

Kevin Scaldeferri kevin@REDACTED
Thu Feb 26 20:56:31 CET 2009

On Feb 26, 2009, at 10:48 AM, Zvi wrote:

> I want to concentrate on my problem domain and think in single  
> paradigm.
> Instead erlang forces you to think in MFAs, funs, messages and  
> gen_server
> primitives.

If you want to have only one way of doing anything, perhaps you should  
try Python.  I hear that's one of their design principles.

> Regaring simple things in other languages - hard in Erlang. This was
> discussed many times and I'll not repeat it: interop, strings,  
> collections,
> defining functions from shell, libraries with principle of maximum  
> surprise,
> etc. I'll just give simple example like loop:
> Ruby:
> 10.times { puts "hi" }

> ...

> or use LC, which is a little shorter, but build 2 unnecessary lists in
> memory:
> [ io:format("hi~n") || _<-lists:seq(1,10) ].

You can also use lists:foreach, which will only require the one  
additional list, but really, as someone else pointed out, this is  
horribly contrived.  How often do you really use Integer#times in  
Ruby, compared to other looping / iteration constructs?  At $WORK I  
just checked our codebase:

each: 1234
map/collect: 35
times: 24
select: 19
reject: 18
inject: 9

Almost ever instance of times() is for the same basic purpose:  
generating a random sequence of length N.  There's probably also a lot  
of uses of each() which should be one of the others, but I work mostly  
with folks with an imperative, not functional mindset.

Anyway, the point is, if times() is something you do a lot, just write  
it and get on with your life.  If it matters to you a lot, make an  
argument for why it's generally important and submit a patch to the  
standard libraries.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090226/47cc7df1/attachment.htm>

More information about the erlang-questions mailing list