Results 1 to 6 of 6
Thread: Bring back the GOTO ;-)
- 09-26-2009, 07:34 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
Bring back the GOTO ;-)
Linux: Using goto In Kernel Code | KernelTrap
Makes an interesting read. The original poster was chastising Linus Torvolds for using goto in linux kernal code. The thread actually contains replies by Torvolds and a longer comment by a subsequent poster pointing out that goto can make the code simpler & smaller. They point out that even if we don't have to count every cycle and byte into today's computers, compact code prevents cache misses, as well as the point that structured constructs are ultimately implemented with jmp instructions with particular reference to the equivilence of the break instruction.
The thread ends with the OP repeating his plea to Torvolds to remove the goto because it violates every tenet that he had learned in studying CS.
If !goto is strictly enforced by a shop, I can understand. It can be misused by the unwashed, and in general, there are very strong reasons for using the general control methods of structured programming. Shouldn't be a fundamentalist religious issue though.
- 09-27-2009, 12:14 AM #2
for sure, sometimes the forest gets lost in the trees. and the right solution is the one that works.. it's just that the mraning of 'right' and 'works' is very subjective, influenced by the constraints from the environment, and changes over time.
In Java, I can't imagine how 'well' a goto would work with the try..catch..finally exception handling constructs.
- 09-27-2009, 12:40 AM #3
The good that goto can do is linear.
The evil that goto can do is exponential.My Hobby Project: LegacyClone
- 09-27-2009, 01:35 AM #4
Goto might be fine in the initial implementation, but it makes maintenance a nightmare -- especially when the person making changes didn't write the code initially... which is most of the time.
- 09-27-2009, 03:50 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 92
- Rep Power
- 0
The points that others have made is that the proper use of goto is:
> exiting a deeply nested control structure. The java labeled break is exactly this usage, as are "break" and "continue" These statements simply prevent alternative uses of goto that give its use a bad name.
> that it would be an alternative to the catch-try, not to be used in the same code.
The link in my first post includes a link to the linux designer guide which provides model code.
A goto should be used sparingly, and my reading has indicated that there are only a couple places that it should be used. The linux kernal authors present error handling code using goto as part of their manuals writing drivers.
Edsger Dijkstra wrote the original "GoTo considered harmful" which was followed by "'goto considered harmful' considered harmful." In the true spirit of recursion or deeply nested statements, there is also '"'GoTo considered harmful' considered harmful" considered harmful'.
I'm in no way suggesting that goto should be used as a matter of course. It should be used only within the concepts of structured programming, but we need to remember that structured program constructs are only a way to allow the compiler to enforce the correct use of jump statements. Perhaps computer architecture has changed enough to allow it, but the only structure at the level is the conditional and absolute jump.
Let me suggest, and I realize this is not strictly true, goto shouldn't make code any harder to maintain than break, continue, and labeled break do. Let me also suggest for the sake of argument, that following correctly written code with goto is no harder than following nested brackets and parens. Not a trivial job in LISP which has no goto. Different languages have different controls structures, all built with jump statements under the hood. Perhaps one should have the freedom to roll your own.
I can be a bit of an iconoclast, and dislike fundamentalist absolutism in all forms, whether it is the Taliban or Rush Limbaugh. As mentioned earlier, I can only shake my head when someone multiply requests Torvolds to stop using goto jumps because it is evil coding incarnate. This is all I am arguing against - the absolutist labeling of the goto as the tool of the devil.Last edited by rdtindsm; 09-27-2009 at 03:59 AM.
- 09-28-2009, 10:02 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
The underlying byte implementation is, frankly, irrelevant to a language like Java, at the level we code at.
Nothing to do with "unwashed" (poisoning the well much?). As pointed out by quad64bit, it's about maintainability, especially in a higher level language like Java. Breaks, continues, multiple returns are all legitimate in their own right as it's pretty obvious where they are going to. I don't use labelled jumps for the simple reason that it is not obvious where things are going to.
Add to that that Java code that get's so complex you feel you need a goto is probably written badly in the first place, gotos are entirely unecessary.
Similar Threads
-
how to use back bean JSF page?
By deru4jesus in forum JavaServer Faces (JSF)Replies: 1Last Post: 03-27-2009, 08:51 AM -
Back button
By Tokajac in forum Web FrameworksReplies: 1Last Post: 11-27-2008, 05:27 AM -
I need a back and forward code
By Jaymz in forum New To JavaReplies: 9Last Post: 10-12-2008, 11:50 PM -
Tim's back!
By tim in forum IntroductionsReplies: 3Last Post: 06-29-2008, 05:50 AM -
goto statement
By bugger in forum New To JavaReplies: 2Last Post: 12-12-2007, 03:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks