I’m still working my way through Crafting Interpre...
# thinking-together
s
I’m still working my way through Crafting Interpreters and just came across a nice piece of content that many here might get a kick out of: at the end of chapter 23 hides a design note, which is a fascinatingly deep critique of Dijkstra’s Goto considered harmful. There’s nothing really surprising or substantially new in there, but I really like how Bob Nystrom argues about the complexities that hide in a paper that practically ended a certain language feature. It’s relatively short and you don’t need to read any other part of the book; it totally stands on its own. Here’s a teaser:
I guess what I really don’t like is that we’re making language design and engineering decisions today based on fear. Few people today have any subtle understanding of the problems and benefits of goto. Instead, we just think it’s “considered harmful”. Personally, I’ve never found dogma a good starting place for quality creative work.
http://craftinginterpreters.com/jumping-back-and-forth.html#design-note
👍 6
❤️ 1
c
For imperative languages with side effects, a gosub is often clearer and more "honest" than function calls. There's some value in distinguishing at language level between "instruction reuse" (sub routine), and "abstracted calculation" (pure function). I've never considered a labelled goto as an anti pattern. Unlabeled line jumps on the other hand are definitely less clear.
👍 1
w
"one of our tribe’s ancestral songs" — I often reflect on "Goto Considered Harmful" for the part: have the code of the program match the concept of what the program does, and the particular example of structured code (sequential statements, conditionals, and loops) for imperative (step-by-step) programs. I think of that part so much, in fact, that I forget about the part that mentions GOTO at all. And in view of the GOTO bit, I suppose callbacks are more harmful in that you are now making the structure dynamic. (To say nothing of continuations.)
👍 2
k
This was great. Dijkstra's paper makes a reasonable case, but on balance may have actually done more harm than good with the flood of imitators and style guides seeking to ban language features purely out of fear. Many of the imitators even copied the 'considered harmful' phrasing, as an offering to be taken more seriously by the masses. Then again, maybe I'm being unfair. Ever were humans prone to following rules without understanding why they exist. If it wasn't Dijkstra we'd find someone else to imitate. Here's a little case I made for goto a few years ago: http://akkartik.name/post/swamp
👍 2
m
While I agree that we shouldn't blindly forbid language features / programming techniques and therefore limit ourselves, it is great to have this kind of pointers / style guides when you are a beginner in programming and need some kind of instructions how to behave. Reasonable defaults / restrictions, so it is harder to hurt yourself. On the other hand, I would be very surprised to see experienced developer that is still convinced that all those rules are untouchable -> naturally, as you grow, you start testing those boundaries and reevaluating them. I think it us up to us to learn to question everything, from time to time, at least a little bit.
r
I highly recommend Knuth's "response" "Structured Programming with go to Statements" which I find a way better piece than Dijkstra's. About dogma, fascinating how things could be different if Niklaus Wirth (!) hadn't change the title from "A case against the goto statement" towards publication.
👍 1
Dijkstra himself wrote something like (paraphrase): "regrettably, it became the cornerstone of my fame even just by the article's title". But imo, I don't think he was bothered too much about it 🙂
j
Labelled continue/break are basically goto anyway and trying to fit certain control flows into that pattern just ends up being harder to read than a real goto. I like Julia's approach of allowing labelled goto but only within a function.
k
Is there any extant language that allows goto another function? Even C has that guardrail. Which makes it hard for us moderns to appreciate just what Dijkstra was arguing against. Personally I think labeled break/continue is great! Is there any pattern it doesn't support?
r
Quickly checked https://riptutorial.com/julia-lang/example/15206/input-validation States: "Although both examples do the same thing, the second (with recursion as opposed to GoTo) is easier to understand." But I find it to be completely opposite and I'd think to beginners as well. What do y'all think?
g
goto reminds me of hyperlinks, so i’m partial to it. i also think the first example is clearer—but i’m also prone to liking things like the not-quite-deprecated-but-very-frowned-upon with statement in javascript, so i may just favor underdogs
goto’s confusion IMO is a classic example of plaintext failing programming—extremely complicated hypertext fiction created by nontechnical authors suggests that better interfaces may make it relatively intuitive
💡 1