![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
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."
|
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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 ![]() |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2005
Posts: 65
Rep Power: 3
![]() |
Goto's are "bad" since they avoid using high level language control structures.
These include (in C): if (x) { ... } else if { ... } else { ... }
while (x) { ... }
do { ... } while (x);
switch (x) { ... }I advise forgetting all about goto. |
|
|
|
|
|
#4 | |
|
Programmer
Join Date: Nov 2005
Posts: 35
Rep Power: 0
![]() |
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. |
|
|
|
|
|
|
#5 | |
|
Programmer
Join Date: Dec 2005
Posts: 65
Rep Power: 3
![]() |
Quote:
while (not last node) {
if (this node = the node i want)
break;
this node = next node;
}start: if (this is the last node) goto end; if (this node = the node i want) goto end; this node = next node; goto start; end: The first is a lot cleaner, especially if you have a situation in which you need nested looping constructs. |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
2 words: spaghetti code
![]()
__________________
Hoes telling me to calm down but I'm like fuck that shit!
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 3
![]() |
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.
__________________
:wq |
|
|
|
|
|
#8 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
I use loops when I can, but I find it easier just to "jump" back to the beginning of a program with a goto.
|
|
|
|
|
|
#10 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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?"
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|