[erlang-questions] erlang sucks

Sean Hinde sean.hinde@REDACTED
Tue Mar 11 23:31:17 CET 2008


On 11 Mar 2008, at 22:11, Mats Cronqvist wrote:

> Sean Hinde wrote:
>>
>>
>> I don't much like the _ when business.
>
> of course, a less (more?) contrived example would be this;
>
> case is_imaginary(Friend) of
>   true -> sad(self());
>   false-> sound(self())
> end.
>
> vs.
>
> FriendIsImaginary = is_imaginary(Friend),
> if
>  not FriendIsImaginary -> sad(self());
>  true -> sound(self())
> end.
>
> where the second one makes my head spin. the point is that you can't  
> ignore the fact that you have to bind X, Y and Z in the 'if' example.

I agree your second version is ugly. That is why I idid not write my  
usage of 'if' in that way ;-)

OTOH in our shop we do have one or two horrible sections of code  
following your convention. In one place we have around 10 variables  
made boolean then scattered throughout a huge if with many clauses of  
complex boolean logic - head spinning indeed! Although it's not that  
obvious how to deal with it in a much better way. We could carefully  
pick it all apart, looking for state space reductions and building  
complex hiearchies of smaller functions, but that is a lot of work for  
perhaps little real gain...

>
>
>> 'if' is also useful when you want to branch on a bunch of unrelated  
>> boolean variables in various combinations:
>>
>> case {X,Y,Z} of
>>    {true, false, _} ->
>>        do_a();
>>        {false, _, true} ->
>>        do_b();
>>    _ ->
>>        do_c()
>> end
>>
>> vs
>>
>> if
>>    X and not Y ->
>>            do_a;
>>    not X and Z ->
>>            do_b;
>>    true ->
>>            do_c
>>    end.
> same here; when you take into account that you have to bind X, Y and  
> Z in the second example, but not in the first, the 'case' version  
> comes out ahead. objectively :>

Why, as the reader of the code, should I care that Z does not have to  
be bound. As the reader of the code I can divine the intention much  
more clearly with the second one, therefore it is better.

> i remain convinced that 'if' is worthless and does nothing but add  
> to the bloat.

1/4 of our code says you are wrong!

Sean




More information about the erlang-questions mailing list