Live data from Hacker News

Goto (2007)

beej.us

1–10 of 207 posts

Re: Goto (2007)

#4
Coming from assembly language, I always found the anti-goto sentiment rather cute. A beautiful restriction, but ultimately arbitrary. Like writing poetry. Or those novels that do not ever use the letter "e". Why would an otherwise sane person write code with "rep" and without ever using "jmp"?

Re: Goto (2007)

#6

Can't say that I'm enthusiastic about goto advice, but - for a second there, I thought the domain was bejeez.us :-P

When bit banging on a slower microcontroller I have found goto has it's uses.

Re: Goto (2007)

#7
The only acceptable use-case for goto I came across was for error handling and cleanup.

If there are multiple points of code failure that all require same cleanup procedure then one section at the bottom is acceptable and can actually keep the code cleaner.

Anything else looks like bad design that ends up producing hard to follow code.

Re: Goto (2007)

#9
Blanket rules like "never use `goto`" are generally not great. A big part of the job of a software developer is knowing when to use what bits of a language.

Sometimes code with `goto` is simply easier to understand. You have to be careful, but dismissing it completely is throwing out a tool.

Re: Goto (2007)

#10
post #4

Coming from assembly language, I always found the anti-goto sentiment rather cute. A beautiful restriction, but ultimately arbitrary. Like writing poetry. Or those novels that do not ever use the letter "e". Why would an otherwise sane person write code with "rep" and without ever using "jmp"?

It's not arbitrary.

The goal is to improve quality by making the code better structured and easier to follow.

For instance, MISRA C rule 15.1 that states that goto should not be used explains: "Unconstrained use of goto can lead to programs that are unstructured and extremely difficult to understand". Indeed, in practice that's often the case.

Post reply on HN