[erlang-questions] Why doesn't Erlang has return statement?
Tue Dec 16 11:43:47 CET 2014
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
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>
> 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
> Thank you
> Aman Mangal
> erlang-questions mailing list
Danil Zagoskin | z@REDACTED
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions