13

I hate when some programmers say that goto should NEVER be used. It's clear that in common cases is not needed but there are situations where goto is the best solution

Comments
  • 4
    Yes, I am always using this, in my Assembly code.
  • 1
    @g-m-f nested for super break
  • 2
    I remember the only time I ever used a GOTO statement in a Pascal program and having someone give me some grief about it.

    It was a compiler, and it was used to terminate the program if the input suddenly (unexpectedly) ended.

    This idiot thought I should have threaded an extra parameter through every single function and procedure along with umpteen testing of that parameter after every call of every procedure and function - because that was more "structured".

    Fuck that.

    Just terminate the program using a GOTO statement to unwind the stack and end cleanly.
  • 6
    I never used a single goto and I don't see a reason to ever use it
  • 0
    I'd use it cause it reminds me of a simpler time, a fun programming experience on my Amstrad CPC 464 and, later, my windows with DOS pcs. Ah, BASIC. The good old days.
  • 3
    goto should never be used
  • 0
    @theactionslacks That's it? That's your argument?

    You think in the example I gave I should have polluted every procedure and function with an extra parameter that had to be constantly tested after every call?

    All to be a purist?

    I am with Ralph Waldo Emerson when he said " A foolish consistency is the hobgoblin of little minds".
  • 0
    @g-m-f It was the 1980s and No, there was no exception handling. Nothing wrong with the code, fairly straight-forward recursive descent parsing which is fine so long as the program it is compiling doesn't suddenly stop mid-statement.

    In which case you unwind slowly and painfully with an extra parameter and umpteen tests, or you just GOTO a stop condition.

    Those were the tools we had.

    GOTO was clearly the most appropriate solution and incidentally is the only time I have ever used a GOTO statement outside of Assembler programming and my teenage years learning to program with Basic.

    I still have the book "Structured Programming" by Dahl, Dijkstra and Hoare which I read around the same time that compiler was written.

    I have no interest in dismissive statements like "GOTO should never be used" by people clearly not interested in understanding the context in which it is clearly appropriate.
  • 1
    @g-m-f from The C++ programming language 4th edition
  • 2
    @g-m-f I don't see how this is a good example. You can easily write the same code without goto. Also you will need an explicit return before the goto which looks kinda strange. Imo the goto just leads to worse code.
    But I agree that in older languages there might be use cases for goto (although I don't see any).
Add Comment