I can see one subtle difference between mane short functions and less longer. If error occurred, back-trace is more useful for shorter functions. <br><br><div class="gmail_quote">2009/1/8 Robert Virding <span dir="ltr"><<a href="mailto:rvirding@gmail.com">rvirding@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">This thread is also a comment to an earlier question by Edward Stow <span><span><<a href="mailto:ed.stow@gmail.com" target="_blank">ed.stow@gmail.com</a>></span></span>.<br>
<br><div class="gmail_quote">
2009/1/8 Richard Carlsson <span dir="ltr"><<a href="mailto:richardc@it.uu.se" target="_blank">richardc@it.uu.se</a>></span><div class="Ih2E3d"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
In efficiency terms, there is no real difference. (If there is one,<br>
it should be considered a compiler problem that might be corrected<br>
at any time - do not waste your time on such microoptimizations.)<br>
Oh, and 'if' switches are no different - they're really a 'case'.</blockquote></div><div><br>Just to qualify Richard's comment. There is no difference at all, in the compiler function clauses are first transformed into a case. <br>
</div><div class="Ih2E3d"><div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">So it's mostly a matter of taste. If your switch makes sense on its<br>
own, i.e., you can give it a reasonably straightforward name, then<br>
by all means break it out as a function - it will make the code<br>
easier to read and make it easier for you to see when there is<br>
common functionality that could be reused rather than copy-pasted.</blockquote></div><div><br>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:<br>
<br>foo(a, m, Z) -> ...;<br>foo(a, n, Z) -> ...;<br>foo(a, o, Z) -> ...<br>...<br><br>it might sometimes better clarify your intent to group function clauses and write:<br><br>foo(a, Y, Z) -><br> case Y of<br>
a -> ...;<br> b -> ...;<br> ...<br> end;<br>...<br></div><br></div>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.<br>
<font color="#888888">
<br>Robert<br><br>
</font><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil<br>
<br>Analyze your data in minutes. Share your insights instantly. Thrill your boss. Be a data hero!<br>Try Good Data now for free: <a href="http://www.gooddata.com">www.gooddata.com</a><br>