I just used a goto!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
"goto" hell? :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Nah, not at all. I have no hate against goto. I think they are noble and worthy operator. And really, all those fancy while, for, do, try/finally loops are just fancy goto in disguise! I just, for some reason, maybe traumatising past experience? Feels the anticipation of painful critics. This is rather odd since it's my own private code base though... :o In fact I did suffer at the hand of anti goto fanatics in the past!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
"goto" hell? :laugh:
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
nah. just traumatising past experience. I suffered at the hands of an anti goto fanatics!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
To avoid this you can put the entire code block in a try. Put the catch at the go to label and throw an exception where you call the goto. Because that’s different somehow!
Socialism is the Axe Body Spray of political ideologies: It never does what it claims to do, but people too young to know better keep buying it anyway. (Glenn Reynolds)
-
nah. just traumatising past experience. I suffered at the hands of an anti goto fanatics!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
The important thing with
goto
is knowing when not to use it - which is most of the time. :laugh:Goto
has its place, but if you can use a structured loop or branch instead then your code is generally cleaner and more maintainable. But very occasionally, using agoto
makes your code cleaner or much more efficient and (provided it's well documented) isn't a problem. It's a problem when it's used because they can: and teachers who introduce it early should be hung, drawn, and quartered (and I don't mean "well hung", "sketched", and "given an apartment").Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
I cannot tell a lie, I used one once. many years ago. I felt awful. I added a twenty line comment apologising for it. I went to bed in trepidation but awoke the next morning to find that I hadn't been struck down dead by the code gods,the fix had worked, the customers were happy and nobody had died. Not sure I'd risk it again, though :)
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
-
Nah, not at all. I have no hate against goto. I think they are noble and worthy operator. And really, all those fancy while, for, do, try/finally loops are just fancy goto in disguise! I just, for some reason, maybe traumatising past experience? Feels the anticipation of painful critics. This is rather odd since it's my own private code base though... :o In fact I did suffer at the hand of anti goto fanatics in the past!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
A lot of these prohibitions are in reality "almost never do such and such." But at the end of the day, other things being equal, it's all about clarity and readability and there will be cases where it's fine. The language directive does exist after all (when it does). Years ago I recall reading a section in the book Code Complete by Steve McConnell where he presented some code using goto and stats showed that almost no developers were able to rewrite it correctly without the goto.
Kevin
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Bully for you. I used one yesterday when my doorbell camera showed some people, with little booklets in their hands, at my door. :)
If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.
-
I cannot tell a lie, I used one once. many years ago. I felt awful. I added a twenty line comment apologising for it. I went to bed in trepidation but awoke the next morning to find that I hadn't been struck down dead by the code gods,the fix had worked, the customers were happy and nobody had died. Not sure I'd risk it again, though :)
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
PeejayAdams wrote:
many years ago
PeejayAdams wrote:
and nobody had died
That's the exact same time my cat died! :wtf: :(( [Dramatic pause] I don't know who you are. I don't know what you want, but I have a very particular lack of skills. I will never be able to find you. But what I do have is two dollars and a Casio wristwatch. You can have one of them.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
To avoid this you can put the entire code block in a try. Put the catch at the go to label and throw an exception where you call the goto. Because that’s different somehow!
Socialism is the Axe Body Spray of political ideologies: It never does what it claims to do, but people too young to know better keep buying it anyway. (Glenn Reynolds)
avoiding goto by using try/catch/exception for expected behavior! genius! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
avoiding goto by using try/catch/exception for expected behavior! genius! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
I was going to chime in that all Exception handling is really goto programming and then I saw DRHuff's excellent reply. People talk about never using goto and then you look at their code and see exception handling and think, "what's this here?" This is also why exception handling can be a pain in the arse. All that jumping around. Consider what happens if you throw an exception in your catch block -- and it is possible. Things can get really ugly jumping here, bouncing there. :laugh:
-
PeejayAdams wrote:
many years ago
PeejayAdams wrote:
and nobody had died
That's the exact same time my cat died! :wtf: :(( [Dramatic pause] I don't know who you are. I don't know what you want, but I have a very particular lack of skills. I will never be able to find you. But what I do have is two dollars and a Casio wristwatch. You can have one of them.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
I'm sure it was the week after your cat died but I'll have the Casio just in case!
Whenever you find yourself on the side of the majority, it is time to pause and reflect. - Mark Twain
-
The important thing with
goto
is knowing when not to use it - which is most of the time. :laugh:Goto
has its place, but if you can use a structured loop or branch instead then your code is generally cleaner and more maintainable. But very occasionally, using agoto
makes your code cleaner or much more efficient and (provided it's well documented) isn't a problem. It's a problem when it's used because they can: and teachers who introduce it early should be hung, drawn, and quartered (and I don't mean "well hung", "sketched", and "given an apartment").Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
The only time "goto" is warranted is if in a nested structure where to accomplish the code control, a flag would need to be set and then checked more than once by the control statements within which this decision to break out is needed. I think I have used it 3 times, and all times, I gave a very good comment as to why it was the proper choice.
-
I was going to chime in that all Exception handling is really goto programming and then I saw DRHuff's excellent reply. People talk about never using goto and then you look at their code and see exception handling and think, "what's this here?" This is also why exception handling can be a pain in the arse. All that jumping around. Consider what happens if you throw an exception in your catch block -- and it is possible. Things can get really ugly jumping here, bouncing there. :laugh:
I think the only time that exception handling should be used is when the current code section does not have any control over the code that is throwing the exception - i.e., it is preferable to check and control something than to rely on an exception that simply does a goto the catch branch.
-
I know "it's bad" and I will be shun by all good developers and rich employers for a thousands years... But I look at it.. I can't find of anything better.. mm, maybe a private inner function (i.e. function inside a method).... followed by misplaced return.... mm....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
it's an old view but as a Hardware/Firmware type I cannot see the hatred for goto, I mean the jmp is a direct map and it produces a smaller binary. Goto is like an axe very useful but very dangerous. An axe wont cut your hand off, misuse it and you could be missing a hand very easily!
-
The important thing with
goto
is knowing when not to use it - which is most of the time. :laugh:Goto
has its place, but if you can use a structured loop or branch instead then your code is generally cleaner and more maintainable. But very occasionally, using agoto
makes your code cleaner or much more efficient and (provided it's well documented) isn't a problem. It's a problem when it's used because they can: and teachers who introduce it early should be hung, drawn, and quartered (and I don't mean "well hung", "sketched", and "given an apartment").Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
OriginalGriff wrote:
teachers who introduce it early should be hung, drawn, and quartered (and I don't mean "well hung", "sketched", and "given an apartment").
My CS teacher introduced them early. However it was more of a "Here is the
goto
statement, here is how it can go horribly wrong, and that is why you should never use it again... ever. If you do, you will fail whatever assignment it was in." sort of way. While it was a bit over dramatic, she did follow up with how to better handle branching/looping logic without them. -
The only time "goto" is warranted is if in a nested structure where to accomplish the code control, a flag would need to be set and then checked more than once by the control statements within which this decision to break out is needed. I think I have used it 3 times, and all times, I gave a very good comment as to why it was the proper choice.
goto is NOT the enemy, it's only when it's used wrongly. but also ... contrary to popular belief disguising it fixes nothing ... if you really need to GOTO, just do it - hiding it only increases the bullshit level. unfortunatelly, there are teachers that tell the kids "GOTO is bad," but then "to do the same thing..." they then go on and teach the kids how to disguise them, i.e. instead use THROW, or stick the [inner] code in a method and return early (i.e. still in an indefinite state). ffs, really! I've got no problems with goto, but I do have issues with (1) shit code, and even more (2) attempts to hide shit code
Message Signature (Click to edit ->)