<div dir="ltr">Hi!<div><br></div><div>I think return statement could make reading the code quite difficult.</div><div>When you debug code not written by you, you could end up in "this function takes these arguments and returns completely unexpected stuff". The next step is looking at code (usually final case) to see how that value could be returned. Return in the middle of a long function would require you to look for returns first.</div><div><br></div><div>As for nested cases. There are some alternatives, each of them has its disadvantages:</div><div> 1. Chaining function calls, each function has a single case. This makes quite hard to add a new argument for the last check.</div><div> 2. Putting all arguments in record and chaining calls — requires wrappers for checks to fetch arguments from a record.</div><div> 3. foldl over function list with arguments+result record as accumulator — so monadic that it is hard to understand, but keeps the processing sequence in single place.</div><div> 4. something like this: <a href="https://gist.github.com/stolen/8537619">https://gist.github.com/stolen/8537619</a> — very uncommon, so may be hard to understand, but flattens cases.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 16, 2014 at 11:05 AM, aman mangal <span dir="ltr"><<a href="mailto:mangalaman93@gmail.com" target="_blank">mangalaman93@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<div><br></div><div>I have seen similar questions before on the forum but I could never understand the reason behind it. Is it due to theoretical reasons such as <i>return </i>statement makes it hard to reason about the program or practical reasons that it is hard to implement it (this doesn't seem right but I cannot think of anything else)?</div><div><br></div><div>Moreover, is there a good alternate to avoid nested case statements? Making more functions just seems tedious. Using <i>catch </i>statement seems another good alternate but my intuition is that it is not good practice, is it?</div><div><br></div><div>Thank you</div><span class="HOEnZb"><font color="#888888"><div>Aman Mangal</div><div><a href="http://www.prism.gatech.edu/~amangal7" target="_blank">www.prism.gatech.edu/~amangal7</a></div>
</font></span><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><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><font face="'courier new', monospace">Danil Zagoskin | <a href="mailto:z@gosk.in" target="_blank">z@gosk.in</a></font></div></div></div>
</div>