A case for unstructured programming
250bpm.com
250bpm.com
What Sustrik asks for here is an imperative context where failure is a native operation. Obviously, this is most useful in a delimited way and this is exactly a maybe monad.
if (foo) {
<whatever>
} else {
if (bar) {
<whatever>
} else {
if (baz) {
<whatever>
} else {
if (spam) {
<whatever>
} else {
...
<etc>
}
}
}
}
It didn't end well.He also wouldn't use break or continue or multiple returns.
As this article says, it led to really really annoying-to-read code.
(cons a
(cons b
(cons c
(cons d . nil))))
(list
a
b
c
d)
a,... being condition/reaction pairs.It's one of the reasons why I wish more languages had a generalized switch statement (i.e. one that accepted arbitrary code as conditions, not just constants compared to a single value), preferably with a way to (explicitly, preferably) code a fall-through.
It means that you cannot necessarily translate it into a jump table, true. But it means that you can write code much more concisely, on the flip side. And it remains slightly readable.
do_stuff1();
while (!condition()) {
do_stuff2();
do_stuff1();
}