There’s something really satisfying about having a working program, and then unlocking totally new functionality by just placing a sneaky goto, though.
Re:Value-Oriented Programming
by MattPalmer1086 on Wednesday February 08, 2023 @12:15PM
(#34711224)
I recently had to use a goto for the first time in years.
Structured programming is fine, but almost no languages except python support the while...else construct.
The semantics are to execute a loop body while the condition is true, and then to execute the else body when it isn't. But if you break out of the while loop, the else is not executed.
You don’t have to use goto. Set a condition then check it accordingly in the block following the while block and all will be fine.
Re:Value-Oriented Programming
by MattPalmer1086 on Thursday February 09, 2023 @05:43PM
(#34732765)
Yes, that is another way, but it involves setting a value and another test for it. This is in the context of an extremely fast algorithm and the overhead here is not acceptable.
It does not always hurt to use goto to implement the correct control flow when required.Arguably, the code is clearer as well.
EDIT: I'd prefer to actually have a while else construct though!
The best experience that i've used is Haskell, where there's no "goto".