Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 12th, 2005, 7:47 PM   #1
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Crazy Challenge =D

OK, here's a challenge for you uber-nerds, and you're not gonna like it.

Write a program/algorithm in a high(er)-level language that uses goto. Bad enough, you say? Here's the killer: the algorithm must not be able to be more elegantly written using higher-level constructs such as loops, comparisons, etc. It has to do something useful - you can't just have twenty nested loops and break out of them with a goto for no reason.

Ready? Go!
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 12th, 2005, 8:20 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
There are few, if any, reasons to use a goto in normal code, aside from deeply-nested constructs, which you have outlawed as a suitable reason. Nevertheless, there are things that can happen in a system that represent fatal conditions. Some of these can be detected by the OS, presuming you have more than a shadow of one. Some cannot. In some instances, an interrupt routine cannot even return without regenerating or compounding the error. One might overwrite the return address and perform a jump in that way, or one might just use a goto. I would say that the most prevalent VALID use is in the handling of such errors. Error handling with try/catch blocks has the benefit of cleaning up a number of things, presuming that the language is written properly, that one would have to take care of overtly in using a simple "goto" to a specific central location from any number of possible failure sites. There isn't any less thinking or work, of course, you just try to put it off on the "other guy".

My typical use of a goto (and they're damned infrequent over the course of many years of programming) IS to exit the nested-loop situation when the exit is not caused by the logical progression of code that entered the loop to begin with, but by the occurrence of an unrelated, real-time event, that dictates getting out NOW, without recourse to following a crumb-trail of flags especially designated for that purpose.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 12th, 2005, 9:13 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Basically, my aim here was to see whether goto is actually a useful keyword to have at all. Thanks for the response, my friend.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 12th, 2005, 9:25 PM   #4
Riddle
Programmer
 
Riddle's Avatar
 
Join Date: May 2005
Location: Nar Shaddaa
Posts: 42
Rep Power: 0 Riddle is on a distinguished road
Send a message via ICQ to Riddle Send a message via AIM to Riddle Send a message via MSN to Riddle
I guess the only time I really use goto is in batch, so..
/me shrugs shoulders.
Riddle is offline   Reply With Quote
Old Sep 12th, 2005, 9:57 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Yes, it has its uses. Unfortunately, it's a temptation to laziness, or a symptom of limited vision. Unless the language restricts its use to a limited scope, it can lead to absolutely unfathomable code for those that run upon it cold. The fact remains that, ultimately, all non-contiguous paths of executions are implemented at the machine-code level by a dead jump, a "goto", conditional or otherwise. I'm looking forward to seeing the responses you get.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 12th, 2005, 10:01 PM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Does TI-Basic count as a higher-level language, i mean it's not ASM. Ok, well, probably not but that's one of the few languages in which i know there is a necessity for GoTo.
__________________

tempest is offline   Reply With Quote
Old Sep 13th, 2005, 2:46 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Anything where a goto can be replaced by a higher-level construct, I guess.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC