![]() |
What's the deal with Goto's?
My programming teacher absolutely hates them. I find them dead usefull and a lot easier to set than loops. I asked him once and all he could come up with is "I dunno, I just don't like them."
|
Short Story: Goto's are EVIL
Longer story: A good design principle is that a module should have one exit point (e.g: return; in C). Goto violates the hell out of that principle rendering your source code unreadable (except by you). Long Story: I'll let someone else do it :) |
Goto's are "bad" since they avoid using high level language control structures.
These include (in C): :
if (x) { ... } else if { ... } else { ... }I advise forgetting all about goto. |
Quote:
Plus...I don't see how you can use them to get around loops. In a current project I'm doing, there's a data structure called a linked list, and i need a loop to do something on every node of the list, there is no way of not doing that without a loop. |
Quote:
:
while (not last node) {:
start:The first is a lot cleaner, especially if you have a situation in which you need nested looping constructs. |
2 words: spaghetti code ;)
|
Gotos are also used in very simple languages when functions are not available- it allows one to reuse code without typing it twice. They really have no point in a higher-level language, though, as other people have said.
|
Yeah goto's are bad, but it's the only way of implementing structured error handling in VB6 for instance. Also there are some specific algorithms that rely on the goto that would be very hard and inefficient to implement otherwise. One thing that perhaps could be more useful is the Gosub...Return structure, similar to a static (variables) dynamic (execution order) inline routine, which allows more controlled jumping, but you're still jumping.
|
I use loops when I can, but I find it easier just to "jump" back to the beginning of a program with a goto.
|
It may be easier to write, but it's definitely harder to read. My advice is this: code everything with the view "If I come back to this in a year's time, will I understand what I've just written?"
|
| All times are GMT -5. The time now is 6:02 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC