Click here to Skip to main content
15,903,362 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Gotoless programming Pin
Reelix28-Feb-12 1:12
Reelix28-Feb-12 1:12 
GeneralRe: Gotoless programming Pin
JackDingler28-Feb-12 2:28
JackDingler28-Feb-12 2:28 
GeneralRe: Gotoless programming Pin
JackDingler28-Feb-12 2:36
JackDingler28-Feb-12 2:36 
GeneralRe: Gotoless programming Pin
reilly9628-Feb-12 2:39
reilly9628-Feb-12 2:39 
GeneralRe: Gotoless programming Pin
Member 797506328-Feb-12 3:41
Member 797506328-Feb-12 3:41 
GeneralRe: Gotoless programming Pin
JackDingler28-Feb-12 5:11
JackDingler28-Feb-12 5:11 
GeneralRe: Gotoless programming Pin
Charlie Ehler28-Feb-12 5:29
Charlie Ehler28-Feb-12 5:29 
GeneralRe: Gotoless programming Pin
SeattleC++28-Feb-12 6:21
SeattleC++28-Feb-12 6:21 
Haters being haters again. Sigh. A little historical context might be helpful here.

If you never programmed in a circa 1980 BASIC, the language did not provide named subroutines or structured control statements, symbolic labels or indentation. GOTO was all you had. To complain about GOTO in a language that has nothing else is just hating. This code implemented a very structured thing, a finite state machine. It was actually best practice for this language that the states were in subroutines and the GOSUBs in the main loop were all together.

Back in the 1960's when many of your moms and dads were children, W Edsgar Dijkstra penned his fameous "GOTO Considered Harmful" article, and Ed Yourdon and others kicked off the "Structured Programming" movement, with its emphasis on single-entry/single-exit programming. (The structured programming movement was a good idea, but it had the same high hype-to-value ratio as Agile does today.) Languages of the day, led by PASCAL, went a little too far, requiring for instance that all functions return out the bottom, so that you often had to use a bit of state to guard if and while statements (WHILE NOT DONE AND ...) so execution would flow down the page and out the end of the function.

People used this as evidence that we did so need GOTO. Then C came along with its break, continue, and return statements and relaxed the rules a bit. There were arguments from the SP folks that these statements were a bad thing, but practitioners won the day.

There were GOTOs to exit code that returned resources. These, said GOTO fans, were evidence that GOTO was unavoidable. This was mostly hogwash, as you could test most resources to see if they'd been allocated, and only return the ones that were. And the arrival of exception handling and the resource-allocation-is-initialization idiom in C++ rendered that discussion moot.

GOTO has few places left to hide. I haven't needed to use a GOTO since 1995, and I have cleaned up many a function by removing GOTOs and fixing up the logic to make it simpler and more correct. I would not miss GOTO if it were removed from C++. It's only there (like many C++ features) for compatibility with old and poorly written C programs.

[pours gasoline on the fire]
GeneralRe: Gotoless programming Pin
Member 205300628-Feb-12 6:35
Member 205300628-Feb-12 6:35 
GeneralRe: Gotoless programming Pin
TNCaver28-Feb-12 10:44
TNCaver28-Feb-12 10:44 
GeneralRe: Gotoless programming Pin
Plamen Dragiyski28-Feb-12 11:30
professionalPlamen Dragiyski28-Feb-12 11:30 
GeneralRe: Gotoless programming Pin
JamesSpencer1-Mar-12 7:23
JamesSpencer1-Mar-12 7:23 
GeneralRe: Gotoless programming Pin
Duncan Goodwin2-Mar-12 6:09
Duncan Goodwin2-Mar-12 6:09 
GeneralRe: Gotoless programming Pin
Duncan Goodwin2-Mar-12 6:38
Duncan Goodwin2-Mar-12 6:38 
GeneralRe: Gotoless programming Pin
theMadCoder7-Mar-12 4:20
theMadCoder7-Mar-12 4:20 
General9000 lines of ... PinPopular
CDP180220-Feb-12 23:03
CDP180220-Feb-12 23:03 
GeneralRe: 9000 lines of ... Pin
Nagy Vilmos20-Feb-12 23:14
professionalNagy Vilmos20-Feb-12 23:14 
GeneralRe: 9000 lines of ... Pin
CDP180220-Feb-12 23:21
CDP180220-Feb-12 23:21 
JokeRe: 9000 lines of ... Pin
Sean Holm20-Feb-12 23:50
professionalSean Holm20-Feb-12 23:50 
GeneralRe: 9000 lines of ... Pin
BobJanova21-Feb-12 0:15
BobJanova21-Feb-12 0:15 
GeneralRe: 9000 lines of ... Pin
fjdiewornncalwe21-Feb-12 5:12
professionalfjdiewornncalwe21-Feb-12 5:12 
GeneralRe: 9000 lines of ... Pin
CDP180222-Feb-12 3:04
CDP180222-Feb-12 3:04 
GeneralRe: 9000 lines of ... Pin
fjdiewornncalwe22-Feb-12 3:19
professionalfjdiewornncalwe22-Feb-12 3:19 
GeneralRe: 9000 lines of ... Pin
CDP180222-Feb-12 4:35
CDP180222-Feb-12 4:35 
GeneralRe: 9000 lines of ... Pin
JackDingler28-Feb-12 5:18
JackDingler28-Feb-12 5:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.