goto... Who uses it?
-
His second stop was the bar, then other places and to write this post. I am assuming he is still enjoying the effects of the local bar. :)
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
-
In SQL - fairly often to jump to the error handler at the end of our sprocs. I'll admit there's no good reason we do this, since it's easy enough for us to avoid this with if statements, but it's a pattern used in our original code and so for consistency we stuck with it:
Create Procedure MyProc as
Begin Tran -- Do stuff... if @@error <> 0 goto errorHandler Commit Tran Return 0
errorHandler:
Rollback Tran
Return 1cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
Real programmers (ones who code in languages like assembly, C and FORTRAN) use it all the time. Rest of us - rarely if ever.
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
Well as an assembly programmer I really don't have much choice. And as for higher level languages, sure, though rarely. There are people who religiously avoid it, but that's just silly. We must remember the reason it is seen as bad, and not open a witchhunt. Introducing a boolean variable just to quit out of a non-enclosing loop makes readability/understandability worse, not better, and refactoring an inner loop into its own function just so you can return out of it creates a bunch of tightly-coupled functions that do nothing useful on their own. Besides, that return would essentially be a goto.
-
That looks bad to me. Aren't you supposed to use
break ;
to jump out of loops? Exception handling will usually bog down the handled block of code.
Q. Hey man! have you sorted out the finite soup machine? A. Why yes, it's celery or tomato.
-
I've not used it in a long time. There are a few of them in our legacy code, but no new code have them; they are mostly used for quick exit of a function to do cleanup.
Nihil obstat
Honestly, I have written at least 1 million lines of code since I have used a goto. Although I do remember using a few gotos in the 1990s. Also long gone from my coding is writing x86 assembly code.
John
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
Me: goto Me;
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
In one of our legacy apps (VB) the goto is used to apply database updates based on the exe version. ErrorHandlers: seperate the update logic for each version and are arranged from top to bottom so that code execution always 'fall through' to the bottom. It may me wrong but it works!
"Go forth into the source" - Neal Morse
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
I put it into my own language just because I wanted to see if I could write a program all in one function which started at the bottom and worked its way to the top. I am not sure why, one of those days. I then immediately removed it from the language spec although the code for it is still in the compiler source - just commented out.
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
I only use it nowadays in assembly (no choice) and scripting languages that don't have good structured programming constructs (ie. if/then/else etc.). I learned programming in the days of early Fortran IV (and actually regressed a little on an older machine with Fortran IID) that only had arithmetic if[^] and computed goto[^] for conditional logic flow. I really came to appreciate the evils of the 'goto' statement and never use them unless there is no other choice. If I use a goto, it will always transfer control downwards, never up. And yes, I use break and continue, and multiple returns in methods.
-- Harvey
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
.Net framework uses that. They just built some fancy keywords that do the same thing but have a different name. For instance, continue.
"Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[^]
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
goto... Who uses it? Only those programmers who want to be slowly boiled in hot oil
If it's not broken, fix it until it is
-
.Net framework uses that. They just built some fancy keywords that do the same thing but have a different name. For instance, continue.
"Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[^]
If you think the 'continue' keyword is anything at all like 'goto', you need to go back to programming 101.
If it's not broken, fix it until it is
-
Thats swift. I'll be the first to admit that I dont have the experience or knowledge of 90% of the people here. Interesting.
DanielSheets wrote:
I'll be the first to admit that I dont have the experience or knowledge of 90% of the people here.
The fact that you care about readability proves that you can't be in the bottom 10% :) Readable code leads to maintainable projects. The better a project can be maintained, the more chances it will survive in the long run.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
I only use it nowadays in assembly (no choice) and scripting languages that don't have good structured programming constructs (ie. if/then/else etc.). I learned programming in the days of early Fortran IV (and actually regressed a little on an older machine with Fortran IID) that only had arithmetic if[^] and computed goto[^] for conditional logic flow. I really came to appreciate the evils of the 'goto' statement and never use them unless there is no other choice. If I use a goto, it will always transfer control downwards, never up. And yes, I use break and continue, and multiple returns in methods.
-- Harvey
-
DanielSheets wrote:
I'll be the first to admit that I dont have the experience or knowledge of 90% of the people here.
The fact that you care about readability proves that you can't be in the bottom 10% :) Readable code leads to maintainable projects. The better a project can be maintained, the more chances it will survive in the long run.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
Eddy Vluggen wrote:
Readable code leads to maintainable projects. The better a project can be maintained, the more chances it will survive in the long run.
.... which is completely offset by his use of 'goto'.
If it's not broken, fix it until it is
-
This isn't a programming question. Anyway... I find it useful in very few situations. It can make for cleaner code if used correctly. Of course, it can also be over used.
-
goto... Who uses it? Only those programmers who want to be slowly boiled in hot oil
If it's not broken, fix it until it is