[erlang-questions] erlang sucks
Mats Cronqvist
mats.cronqvist@REDACTED
Tue Mar 11 23:11:21 CET 2008
Sean Hinde wrote:
>
> On 11 Mar 2008, at 19:26, Mats Cronqvist wrote:
>
>> Sean Hinde wrote:
>>>
>>> On 11 Mar 2008, at 12:47, Mats Cronqvist wrote:
>>>
>>>>
>>>> * 'if' is completely worthless, and should ideally be obsoleted.
>>>
>>> No, no no! I like 'if' It allows some neat constructs that are
>>> horrible with case.
>>
>> i was afraid no one was going to bite... still, I'd like an example
>> or 2.
>
> I'm thinking of things like:
>
> case X of
> _ when X == abc; X == xyz ->
> do_abc_or_xyz();
> _ when X == '123', X == '456' ->
> do_123456()
> '123' ->
> do_123_only();
> fred ->
> do_fred()
> end
>
> vs
>
> if
> X == abc;
> X == xyz ->
> do_abc_or_xyz();
> X == '123',
> X == '456' ->
> do_123456();
> X == '123' ->
> do_123_only();
> X == fred ->
> do_fred()
> end
>
> 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.
> '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 :>
i remain convinced that 'if' is worthless and does nothing but add to
the bloat.
mats
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mats_cronqvist.vcf
Type: text/x-vcard
Size: 179 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080311/f68fa379/attachment.vcf>
More information about the erlang-questions
mailing list