[erlang-questions] Why doesn't Erlang has return statement?
Danil Zagoskin
z@REDACTED
Tue Dec 16 11:43:47 CET 2014
Hi!
I think return statement could make reading the code quite difficult.
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.
As for nested cases. There are some alternatives, each of them has its
disadvantages:
1. Chaining function calls, each function has a single case. This makes
quite hard to add a new argument for the last check.
2. Putting all arguments in record and chaining calls — requires wrappers
for checks to fetch arguments from a record.
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.
4. something like this: https://gist.github.com/stolen/8537619 — very
uncommon, so may be hard to understand, but flattens cases.
On Tue, Dec 16, 2014 at 11:05 AM, aman mangal <mangalaman93@REDACTED>
wrote:
> Hi everyone,
>
> 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 *return
> *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)?
>
> Moreover, is there a good alternate to avoid nested case statements?
> Making more functions just seems tedious. Using *catch *statement seems
> another good alternate but my intuition is that it is not good practice, is
> it?
>
> Thank you
> Aman Mangal
> www.prism.gatech.edu/~amangal7
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
--
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141216/d6a196f9/attachment.htm>
More information about the erlang-questions
mailing list