[erlang-questions] if vs. case (long)
Mats Cronqvist
mats.cronqvist@REDACTED
Thu Mar 13 09:12:20 CET 2008
Ulf Wiger wrote:
> 2008/3/13, Jay Nelson <jay@REDACTED>:
>
>
>> My default instinct in erlang is to use case because I know it can
>> always be easily expanded to include more branches, and it guarantees
>> that all legal cases are enumerated so nothing is hidden in the order
>> of branches:
>>
>> Var = computeStuff(),
>> case DebugOn of
>> true -> log(Var);
>> false -> ok
>> end,
>>
>
>
> A colleague of mine would most definitely write this as
>
> DebugOn andalso log(Var).
>
> I'll save him the trouble of pointing that out. (:
>
> We've had some discussions about whether this is good style.
>
> BR,
> Ulf W
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
that's too verbose, and log/1 has to return a boolean. here's the
Right Way(tm);
[log(Var) || DebugOn].
mats
p.s. sarcasm! this construct is only to be used in obfuscated erlang
competitions!
-------------- 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/20080313/6171c0d9/attachment.vcf>
More information about the erlang-questions
mailing list