<p dir="ltr">A quick thought on the case vs function question...</p>
<p dir="ltr">I personally tend to eventually replace case expressions shortly after writing them as at that point it becomes clearer to me "what's going on" there. If a well named function can clarify what's gong on, I'll use it. Otherwise I leave the case expression alone.</p>
<p dir="ltr">I end up with very few case expressions.</p>
<p dir="ltr">I think the example you give - translating the shape of some result - is arguably a good one for sticking with case... As a function can start to take more effort to understand at a glance than the case.</p>
<p dir="ltr">I'd stick with the rule "make it obvious what's going on" and use your best judgment along the way. If you're working with a team, see what people like over time and converge on that.</p>
<div class="gmail_quote">On Mar 2, 2015 8:21 PM, "Judson Lester" <<a href="mailto:nyarly@gmail.com">nyarly@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As I'm becoming more comfortable and proficient in Erlang, I'm finding there there are interesting patterns that begin to emerge that I'm not sure I've seen elsewhere. I'm wondering if there's a collection somewhere, maybe c2 style?<div><br></div><div>One example is a complicated data processing: I've started creating a special purpose record and dispatching based on its fields. That includes short-circuiting on errors, constructing syntheses from simpler data, etc. Since I've stumbled onto it, I've been really liking how it can bring the full force of pattern matching to complex processing. I do worry that it's a bit of a smell though. If the processing can be simplified, that might be better, but it's better, imo, than a long ladder of maybe_compute_other_thing style functions.</div><div><br></div><div>And an open question (for me): when to use case/if versus function heads? Roughly, I've been using cases to reformat the returns of a function call, but the decision trips me up every time.</div><div><br></div><div>Judson</div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div>