[erlang-questions] erlang sucks

Nohl Attila Rajmund Attila.Rajmund.Nohl@REDACTED
Tue Mar 11 23:36:14 CET 2008


On Tue, 11 Mar 2008, Ulf Wiger (TN/EAB) wrote:

> attila.rajmund.nohl@REDACTED skrev:
>> 
>> There's one more thing that sometimes drive me nuts - due to the lack of
>> decent 'if' statement, new functions are written instead of branches of
>> a conditional statement. So I see a lot of code like this:
>> do_something(X, Y) ->
>>      really_do_something(X, Y).
>> 
>> really_do_something(a, Y) ->
>>      really_really_do_something(a, Y);
>> ...
>> 
>> really_really_do_something(a, b) ->
>>      ... % could be a one liner
>> 
>> The problem is that the really_really_do_something is way to long to
>> type for people whose editor can't complete function names, so they'll
>> write rrds instead - which is very non-intuitive. I've just checked and
>> our code contains more than 150 functions with 3 character name, more
>> than 50 functions with 2 character name and more than 150 functions with
>> 4 character name. Some of these names actually make sense (e.g. get,
>> set), but most of them do not - and I don't like function names that do
>> not make sense. I haven't seen this practice in C++ or Java projects.
>
> One very good reason for doing this(*) is that Erlang has excellent
> trace facilities for function calls, but no ability to trace on
> branching.

Yes, erlang has excellent trace facilities, it shows me that the 'rfmm'
function was called - unfortunately it doesn't show that which of the 10
rfmm functions was called. OK, I could figure out from the argument list
(also in the trace), but when the argument list is 100 lines long (you
have to pass the whole damn state as a parameter!), I just don't find it
that useful. Actually it's faster to insert some io:format calls into
the code and check the output.

> I tend to agree that it often leads to less readable
> code, but I don't agree that it's because of 'if' - at least not
> in the cases where I've observed it in our code.
>
> (*) this = using many small functions - not using illegible function
>    names, which is just silly.

I agree that using small functions is a good practice. However, many one
liner function just makes following the code flow harder, because in the
end the code is longer. One pattern I often see is:

some_function(X, Y, Z) ->
     rc(handle_some_function(X, Y, Z)).

rc(ok) ->
     ok;

rc(error1) ->
     handle_error1();

rc(error2) ->
     handle_error2().

I think this is just bloat, it's a lot more elegant even in pesudo-C:

some_function(X, Y, Z) {
     rc=handle_some_function(X, Y, Z);
     if (error1==rc) {
         handle_error1();
     }
     else if (error2==rc) {
         handle_error2();
     }
}

It's shorter by only 2 lines, still, my eyes don't have to jump around
that much when I follow the code. I guess this could be done in erlang
with if's, but the crusaders against if's have reached our design rule
document :-)
 				Bye,NAR
-- 
NOHL Attila Rajmund,  Research Fellow
Ericsson R&D, Hungary, IP Services      Phone: +36-1-437-7471
H-1037 Budapest, Laborc u. 1.           Fax:   +36-1-437-7792
Email: Attila.Rajmund.Nohl@REDACTED



More information about the erlang-questions mailing list