[erlang-questions] case or clause
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 <>
> This thread is also a comment to an earlier question by Edward Stow <
> 2009/1/8 Richard Carlsson <>
>> 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
> foo(a, Y, Z) ->
> case Y of
> a -> ...;
> b -> ...;
> 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.
> erlang-questions mailing list
--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...
More information about the erlang-questions