Click here to Skip to main content
15,900,378 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
Member 834855428-Feb-12 5:44
Member 834855428-Feb-12 5:44 
GeneralRe: Gotoless programming Pin
cpkilekofp28-Feb-12 5:53
cpkilekofp28-Feb-12 5:53 
GeneralRe: Gotoless programming Pin
Member 316697428-Feb-12 3:14
Member 316697428-Feb-12 3:14 
GeneralRe: Gotoless programming Pin
George Dennie28-Feb-12 4:36
George Dennie28-Feb-12 4:36 
GeneralRe: Gotoless programming Pin
cpkilekofp28-Feb-12 6:14
cpkilekofp28-Feb-12 6:14 
GeneralRe: Gotoless programming Pin
JackDingler28-Feb-12 2:35
JackDingler28-Feb-12 2:35 
GeneralRe: Gotoless programming Pin
ClockMeister28-Feb-12 3:51
professionalClockMeister28-Feb-12 3:51 
GeneralRe: Gotoless programming Pin
cpkilekofp28-Feb-12 8:01
cpkilekofp28-Feb-12 8:01 
CodeBubba wrote:
GOTO makes sense in a lot of contexts, in others it doesn't. Whatever construct
allows you to express the idea in code most elegantly is what you
use.
 
I have to laugh at the religious fervor that develops over
this particular subject.
 


It's not religious fervor; it's the voice of victims of the GoTo Holocaust saying "Never again!" I speak for myself and many, many others who had to maintain code written in structured languages by programmers who didn't care to structure their code. At the time I entered programming as a profession, Dykstra's "GoTo Considered Harmful" had been published for over a decade yet many programmers still disdained use of structures even after moving to languages like C which supported a rich set of control and loop structures. This was called "job security" - after all, if only the original programmer could explain his code, obviously he needed to be kept happy, and the less readable the code was the better it served the programmer's purpose.

The biggest problem with GoTo is that is does NOT "express an idea"; it just tells you where to go next. Thus, while the code implements the algorithm, it does not express it to the reader.

That hasn't kept me from occasionally letting a goto remain somewhere where it would have been too time-consuming to factor it out. Also, goto is vital in one particular context: when otherwise code would be too large for the available memory space. Before virtual memory (i.e. the days of MSDOS) I helped maintain multi-megabyte programs loaded 256k at a time into the PC's memory, and gotos could sometimes eliminate code repetition in complex algorithms that resisted refactoring (e.g. they worked, but no one really knew how). So, I do know that gotos are sometimes necessary.

However, it is my considered opinion based on years of experience maintaining code with gotos along with years of experience first using structured programming then other forms (functional, declarative, later OOP) that if goto isn't absolutely required to solve the problem, then it is a maintenance menace because it does not express anything, requiring a programmer to parse the branches in order to understand the algorithm being expressed. This may not seem like anything to someone who routinely uses gotos, especially if you work within a group that shares the same habits and code styles, but do you remember how long it took to become an expert at what someone else's code would produce? (If your answer is "not long at all", I suggest you've never worked on anything that I would call complex). Maintenance of code in a business environment means you have to train your fellows in what you do, so if a truck turns you into a greasepot on the highway your business fails to fail because the next guy can take up approximately where you left off. I've got MSCS-level algorithms that give my partner in crime headaches, and they are all nicely structured code encapsulated in sensible objects, AND he's got a graduate degree in a real engineering discipline (thus, he's not a slouch) - I could have used a goto here and there to shorten code length, but how long would it take to explain what that's doing when he's struggling with the rest of the logic?

To anyone who has shared my experience, saying that "GOTO makes sense in a lot of contexts" suggests you "know" things that just aren't true. Show us where you thinks it makes sense, please. Who knows, after all this time I might just learn something new.
GeneralRe: Gotoless programming Pin
ClockMeister28-Feb-12 8:19
professionalClockMeister28-Feb-12 8:19 
GeneralRe: Gotoless programming Pin
jschell28-Feb-12 13:44
jschell28-Feb-12 13:44 
GeneralRe: Gotoless programming Pin
Merlin8728-Feb-12 4:28
Merlin8728-Feb-12 4:28 
GeneralRe: Gotoless programming Pin
Peter Grogono28-Feb-12 6:09
Peter Grogono28-Feb-12 6:09 
GeneralRe: Gotoless programming Pin
AspDotNetDev22-Feb-12 12:21
protectorAspDotNetDev22-Feb-12 12:21 
GeneralRe: Gotoless programming Pin
CDP180223-Feb-12 13:29
CDP180223-Feb-12 13:29 
GeneralRe: Gotoless programming Pin
AspDotNetDev23-Feb-12 14:27
protectorAspDotNetDev23-Feb-12 14:27 
GeneralRe: Gotoless programming Pin
CDP180223-Feb-12 16:58
CDP180223-Feb-12 16:58 
GeneralRe: Gotoless programming Pin
leppie27-Feb-12 18:59
leppie27-Feb-12 18:59 
GeneralRe: Gotoless programming Pin
Jonathan C Dickinson27-Feb-12 21:27
Jonathan C Dickinson27-Feb-12 21:27 
GeneralRe: Gotoless programming Pin
leppie27-Feb-12 22:36
leppie27-Feb-12 22:36 
GeneralRe: Gotoless programming Pin
DerekT-P28-Feb-12 1:36
professionalDerekT-P28-Feb-12 1:36 
GeneralRe: Gotoless programming Pin
Kirk Wood28-Feb-12 1:46
Kirk Wood28-Feb-12 1:46 
GeneralRe: Gotoless programming Pin
Jonathan C Dickinson28-Feb-12 1:56
Jonathan C Dickinson28-Feb-12 1:56 
GeneralRe: Gotoless programming Pin
Kirk Wood28-Feb-12 1:51
Kirk Wood28-Feb-12 1:51 
GeneralRe: Gotoless programming Pin
Anthony Appleyard27-Feb-12 19:24
Anthony Appleyard27-Feb-12 19:24 
GeneralRe: Gotoless programming Pin
GuyThiebaut27-Feb-12 20:39
professionalGuyThiebaut27-Feb-12 20:39 

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.