On Friday, July 27, 2012 03:23:27 Era Scarecrow wrote: > On Friday, 27 July 2012 at 00:57:15 UTC, bearophile wrote: > > Stuart: > >> Why does D have GOTO? I haven't used GOTO in over a decade, > >> because it's truly evil. > > > > Gotos are not so evil. Just use them when they are useful and > > they can't be replaced by structured programming. In D I create > > finite state machines at compile-time that use gotos, they are > > quick. > > As mentioned, why would GOTO be evil? > > http://en.wikipedia.org/wiki/BASIC > > I'm remembering back when i used an Atari (For others, > Commodore64 and Apple IIe), where the BASIC programming language > supplied (via rom or built in) didn't have function calling and > instead everything used GOTO statementes (Or GOSUB).
That's precisely the sort of environment where goto was originally vilified. It was being used heavily for flow control. if statements, while loops, function calls, etc. all effectively use goto. They just do it for you. it was originally being argued that safer constructs should be used instead of gotos. Now, we have way more safe constructs for moving around in code then was the case when goto was originally vilified, and everyone is using those constructs rather than goto. But the stigma remains and everyone is used to thinking of goto as evil. > Obviously spaghetti came about easily, but when the GOTO is > dropped to only being a logical jump when no other options are > available. Consider half a dozen GOTO's with labels nearby vs > thousands. Exactly. Talking about goto as being evil now is almost silly when you think about it. It's been almost universally reduced to being use in the cases where it's truly useful. It's just not used anymore in the cases where it _is_ arguably evil. So, the problem that existed when goto was originally vilified has pretty much gone away, and reflexively declaring goto evil and freaking out over any use of it is actually harmul. It's a useful construct when used properly. It just shouldn't be used when there are better alternatives. - Jonathan M Davis