Re:What can be learned from studying long gone development p...
by Joker_vD on Monday August 16, 2021 @08:18AM
(#28197189)
Well, it's slightly more powerful that pattern-matching Result because in case of nested loops you can short-circuit right to the very top loop.
Writing corresponding nested maps/folds is generally quite unsightly. Plus the resulting code may be non-tail-recursive which means that the sentinel EarlyExit value will get checked and re-returned for every function in the call stack on such exit.
This loop construct, however, basically introduces locally scoped continuations that you can directly return to. Of course, it's possible to optimize nested maps/folds down to this form, but it requires very heavy inlining — Haskell does it because it's semantics allow deforestation, but does Rust do it?
Re:What can be learned from studying long gone development p...
by andi999 on Monday August 16, 2021 @08:09AM
(#28197129)
Yes, I read it and I agree with your text. My point was just that goto is not evil, sometimes it is your best option (like in the parent if loops do not have break).
On a side one could argue that early returns, while often used, are not structured programming and a goto in disguise.
My favourite part of the Knuth paper is this:
This is pattern-matching on a Result<(), String>, in 1974. How adorable!It’s a shame that innovation in this area has stagnated so much: most languages only feature IF, WHILE, FOR, single-level CONTINUE/BREAK, SWITCH (with fallthrough), and GOTO as an escape hatch in case the others are insufficient, just because they are so familiar. Only now languages like Python or Java are getting any form of pattern matching. Though props to the latter for at least allowing to break multiple loops by way of labelling the outermost one.