[erlang-questions] case or clause

Hynek Vychodil vychodil.hynek@REDACTED
Fri Jan 9 00:25:51 CET 2009


I can see one subtle difference between mane short functions and less
longer. If error occurred, back-trace is more useful for shorter functions.

2009/1/8 Robert Virding <rvirding@REDACTED>

> This thread is also a comment to an earlier question by Edward Stow <
> ed.stow@REDACTED>.
>
> 2009/1/8 Richard Carlsson <richardc@REDACTED>
>
>>
>> In efficiency terms, there is no real difference. (If there is one,
>> it should be considered a compiler problem that might be corrected
>> at any time - do not waste your time on such microoptimizations.)
>> Oh, and 'if' switches are no different - they're really a 'case'.
>
>
> Just to qualify Richard's comment. There is no difference at all, in the
> compiler function clauses are first transformed into a case.
>
>
>> So it's mostly a matter of taste. If your switch makes sense on its
>> own, i.e., you can give it a reasonably straightforward name, then
>> by all means break it out as a function - it will make the code
>> easier to read and make it easier for you to see when there is
>> common functionality that could be reused rather than copy-pasted.
>
>
> Sometimes I also do the opposite and use function clauses / case as a means
> of grouping to emphasize a code structure. So while you can write:
>
> foo(a, m, Z) -> ...;
> foo(a, n, Z) -> ...;
> foo(a, o, Z) -> ...
> ...
>
> it might sometimes better clarify your intent to group function clauses and
> write:
>
> foo(a, Y, Z) ->
>     case Y of
>         a -> ...;
>         b -> ...;
>         ...
>     end;
> ...
>
> As already noted there is no difference in efficiency. This is probably not
> a PC thought for a functional language I sometimes feel that you can get too
> of a good thing and have too many small functions and it can make reading
> the whole more difficult.
>
> Robert
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090109/6b03fdff/attachment.htm>


More information about the erlang-questions mailing list