Comment On The RedirectException

Hannes writes, "I'm currently working on maintaining rewriting an application from the early days of ASP.NET (c. 2001) to be all AJAXy and Web 2.0. One of the first things I stumbled over when I first fired up the debugger was a strange exception - the RedirectException - that got thrown on almost every page. Sometimes, it was thrown more than once in the page lifecycle, but it never made it up to the front-end. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The RedirectException

2008-04-07 08:08 • by Mithrandir (unregistered)
Impressive - but not all that uncommon to use exceptions for logical rerouting since GOTO is outlawed.

At least it was properly named for what it did.

Re: The RedirectException

2008-04-07 08:11 • by Anonymous (unregistered)
188351 in reply to 188350
It's at the end of each code block in an if/elseif/else statement. Removing the try/catch block and exception throwing would produce the exact same results.

Re: The RedirectException

2008-04-07 08:12 • by Woohoo (unregistered)
ouch...

you see the same form of abuse in Java a lot: using exceptions for flow control...

*absolutely* worst thing I ever saw was this:


void someMethod()
{
try
{
... // ~300 LOC
if (someExitCondition)
{
String s = null;
s.length();
}
... // ~300 LOC
}
catch(Exception ex)
{}
}


The developer's worst sins in ascending cruelty:

1) creating a much too long method body (the whole system was certainly not OO)
2) not knowing about the "throw" statement and using a dumb deliberate error condition to force an exception
3) using an empty "catch" block with a generic exception type, thus rendering all real exception handling completely moot in this method
4) not knowing about the "return" statement (!!!)

number 4 is the real killer, of course... ;o)

Re: The RedirectException

2008-04-07 08:16 • by dave (unregistered)
188353 in reply to 188352
Woohoo:
ouch...

you see the same form of abuse in Java a lot: using exceptions for flow control...

*absolutely* worst thing I ever saw was this:

/** SNIP **/


I hope that's not created by someone you work with. If it is, I weep for you.

Re: The RedirectException

2008-04-07 08:18 • by Ian (unregistered)
he probably did this because .Net throws an exception if you do a redirect inside a try block.
You have to either redirect with the 'endResponse' flag set to false, or catch a ThreadAbort exception and ignore it.

Re: The RedirectException

2008-04-07 08:21 • by Bill (unregistered)
I hate to say it but I have been tempted by this before. Its not so much just a substitute for GOTO because of the stack unwinding and deallocation happening just the way you'd want it.

I did decide against it :)

Re: The RedirectException

2008-04-07 08:22 • by Johny Mark (unregistered)
I've seen worse stuff. I've been working methods with code wrapped around a try...except block, and the except block stored the exception message in a string! Sometimes it's really, really, REALLY difficult to debug the code, specially when we're dealing with lots of methods calling each other and a single exception is ignored.
Oh, and the last guy didn't know about static variables. There is a "ClassFunctions" class with lots of utility vars and functions. No idea why.
BTW: the Class prefix is required. Yes, it is very, very stupid, but it's required, documented and I can be punished for not following such ridiculous standard. We don't even have source control, we don't have a decent bug tracking system, but we have a document telling us to prefix classes with "Class". Go figure.

Re: The RedirectException

2008-04-07 08:25 • by me (unregistered)
188359 in reply to 188356
I hate to say it but I have been tempted by this before.

Go. Find. Another. Job.

Seriously. You're not fit to be a programmer.

Re: The RedirectException

2008-04-07 08:36 • by Joe Scylla (unregistered)
Well, goto got stigmatized and now many are using Exceptions for flow control (and sometimes write better readable code).

Goto wasn't that bad.

Re: The RedirectException

2008-04-07 08:44 • by ubersoldat
Why? My Eyes!!! But... why? Please, go find the person who did this and ask him/her in wtf he was thinking of. Now my mind hurts. There goes my Monday productivity.

hmmmm... Firefox spell checker thinks that monday should be Monday only.

Re: The RedirectException

2008-04-07 08:45 • by OzPeter
188363 in reply to 188360
Joe Scylla:
Well, goto got stigmatized and now many are using Exceptions for flow control (and sometimes write better readable code).

Goto wasn't that bad.


What I find ironic is the the aboslute belief that Goto's are bad, yet when you get down to the bare metal thats fundementally what a CPU runs on.

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)

Re: The RedirectException

2008-04-07 08:48 • by T (unregistered)
Wow!

Exceptions are not only meant for error handling, it's a useful mechanism built into the language.

Saying that this is like GOTOs because you could do it with ifs/etc applies to error handling also. Take a minute to think before posting template answers.

In certain situations throwing something is somewhat more elegant, and while it is not recommended, it is certainly not frowned upon.

FYI TurboGears uses the same redirect method:
raise redirect("url")

http://www.lucasmanual.com/mywiki/TurboGears#head-b10112a311bd01497b2e06f32a9b3f0cb9d52561

Re: The RedirectException

2008-04-07 08:52 • by Matt (unregistered)
188365 in reply to 188363
OzPeter:
Joe Scylla:
Well, goto got stigmatized and now many are using Exceptions for flow control (and sometimes write better readable code).

Goto wasn't that bad.


What I find ironic is the the aboslute belief that Goto's are bad, yet when you get down to the bare metal thats fundementally what a CPU runs on.

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


GOTOs don't kill applications- Programmers kill applications.

Re: The RedirectException

2008-04-07 08:57 • by dkf (unregistered)
188366 in reply to 188363
OzPeter:
Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)
Welcome to the NGA - the National Goto Association. Tonight we're having pasta for our association dinner; spaghetti, to be exact.

Re: The RedirectException

2008-04-07 08:58 • by Claxon
188367 in reply to 188364
T:
Wow!

Exceptions are not only meant for error handling, it's a useful mechanism built into the language.


But you have to agree that they are intended to be used for exceptional circumstances. This just looks like it runs them as a matter of course for every option the user has.

Re: The RedirectException

2008-04-07 08:59 • by Jobsworth (unregistered)
188368 in reply to 188363
OzPeter:
Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


As long as you don't go riding in chariots with stone tablets, shouting profanities at statues while eating green cookies, you'll be just fine.

Captcha: amet
And last time it was dolor.
I think it's feasable for a dedicated spammer to write an algoritm that would also try lorem, ipsum, and friends.

Re: The RedirectException

2008-04-07 08:59 • by ThePants999
188370 in reply to 188352
Woohoo:
4) not knowing about the "return" statement (!!!)

number 4 is the real killer, of course... ;o)

Our coding standards prohibit the use of "return" anywhere but the end of a method, the theory being that it's harder to read the method as a whole if you can jump out from anywhere. (We do allow "break" though, and in C you can use "goto EXIT_LABEL" - go figure.)

Re: The RedirectException

2008-04-07 09:03 • by fred (unregistered)
188371 in reply to 188359
I hate to say it but I have been tempted by this before.
Go. Find. Another. Job.

Seriously. You're not fit to be a programmer.


That is a stupid thing to say. Making errors is the mark of good programmers, if you are willing to learn from them.

I am probably a better programmer than you are, but I have been tempted by this, and actually used it once in some form of it in a project. It did seem the easiest solution (it was for reading a file, and I generated an EndOfFile exception at the end). It was a stupid idea, but it did work and was easy to implement. Of course, the drawback is in maintenance/evolution, and I ended up rewriting it sanely a few years later (a 15 minutes job).

So, I think it is natural to be tempted by it, and programmers are quite good at persuading themselves that the first idea that crosses their mind is the correct one ("well, that situation [end-of-file, or redirection] is exceptional, so it make sense to use an exception for it, so I don't clutter the normal code path with code that handles that specific case"). It takes experience to understand why it is such a bad idea, and experience only comes with errors.

Btw, I think the CS courses should teach maintenance, as that is 80% of the work of a programmer (and in the other 20%, when you write new code, you actually have to think about maintenance, by you or others). Something like asking students to make modifications to code with design flaws, so they could learn the hard way why some ideas are bad.

Re: The RedirectException

2008-04-07 09:05 • by BadReferenceGuy (unregistered)
188372 in reply to 188363


What I find ironic is the the aboslute belief that Goto's are bad, yet when you get down to the bare metal thats fundementally what a CPU runs on.

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


I direct you to Dijkstra:
http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF

He had very specific reasons why he considered goto to be a bad idea.

Re: The RedirectException

2008-04-07 09:13 • by KenW
188373 in reply to 188364
T:
Exceptions are not only meant for error handling, it's a useful mechanism built into the language.


They're not meant for normal things, either. They're called "exceptions" for a reason. They're to handle exceptional things - things that you don't expect to happen during normal execution. Things like hard-coded redirects because conditions aren't met isn't unexpected; obviously you DID expect them, because you wrote the code to handle them with the exception. Handle them the correct way instead.

Using exceptions to do things you expect is stupid. There's overhead involved in setting up things to raise an exception. Wasting that overhead for something you know will probably happens is idiotic. If you write code that way, stay away from my shop.

Re: The RedirectException

2008-04-07 09:17 • by Waffle (unregistered)
188374 in reply to 188363
OzPeter:

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


If you're interested, I heard of a recent vacancy for that very profile.

Re: The RedirectException

2008-04-07 09:23 • by FDumlao (unregistered)
I know someone said that ASP.NET throws an exception if you try to redirect inside of a try block, however I'm willing to be the try block is there because there is some logic right there on that ASPX page that should be in the DAL or BLL...

If the code was in the right place in the first place he probably wouldn't have had to use a try/catch in the page itself, thereby freeing him up to do something more sensible in the ASPX page.

Oh, and GOTO's r teh suck. Not because they cause a performance problem - because they are hard to friggin read. They cause a linear line of thought in your brain to have to branch off to some other part of the code. It's ugly too. If you need to break that code out why not just write a private method to handle it?

Re: The RedirectException

2008-04-07 09:28 • by mtu (unregistered)
I'm working on a derivative of xchat 1.0 (with some features backported from xchat 2.x) which we're cleaning up for efficiency and sanity - it's a goto nightmare. I was working on removing all gotos from the code, and had a hell of a time figuring out what the author wanted to do. Most of the time though, I could rewrite the functions to not use goto without even introducing any new variables, and the legibility has improved greatly.

Captcha: plaga. Indeed.

Re: The RedirectException

2008-04-07 09:30 • by OzPeter
188377 in reply to 188372
BadReferenceGuy:
I direct you to Dijkstra:
http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF

He had very specific reasons why he considered goto to be a bad idea.


Oh I totally agree with Dijkstra and I have been using object orientated methods in my own programming since the 80's.

My point was that people blindly demonise Gotos without realising the systems they use are actually built on them at a fundemental level. In fact "continue" and "break" statements are only thinly disguised Gotos as well.

Re: The RedirectException

2008-04-07 09:31 • by Martin Dreier
188378 in reply to 188363
OzPeter:
[...](damn am I starting to sound like an NRA spokesperson???)


They have a vacancy for one.

SCNR.

Re: The RedirectException

2008-04-07 09:52 • by xtremezone
188379 in reply to 188360
Joe Scylla:
Well, goto got stigmatized and now many are using Exceptions for flow control (and sometimes write better readable code).

Goto wasn't that bad.

goto is just as unnecessary in this particular case! Sadly, I've been developing with ASP/VBScript for the past year so .NET is more of a dream to me at this point, but you should achieve the exact same behavior more efficiently and with less code with something like...
if(!isCustomer) 

{
-- snip lots of code to process a new order --
Response.Redirect("/Orders/NewOrderShipping.aspx")
}
else if(isQuickOrder)
{
-- snip more order processing code --
Response.Redirect("/Orders/Confirm.aspx")
}
else
{
-- snip even more order processing code --
Response.Redirect("/Orders/SelectShipping.aspx")
}

goto shouldn't have even come up...

Re: The RedirectException

2008-04-07 09:59 • by FredSaw
Back in the pre-dotnet days I worked at a company which used VB as our development language. Its only built-in error trapping was by means of "On Error Goto [label]". The most common label chosen for the error handling routine was "Hell":

On Error Goto Hell

Re: The RedirectException

2008-04-07 10:00 • by Jules (unregistered)
This just made me laugh! I never would have thought of this one.

Re: The RedirectException

2008-04-07 10:06 • by NiceWTF (unregistered)
188384 in reply to 188363
OzPeter:

What I find ironic is the the aboslute belief that Goto's are bad, yet when you get down to the bare metal thats fundementally what a CPU runs on.


Yes, this must be why we all write machine code manually - after all that is fundamentally what a CPU runs on.

Or perhaps programming languages and compilers where invented for a reason, such as abstracting away from low-level machine implementations.


Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself


As an implementation mechanism (where programmers don't have to look at them), goto's are fine. As a high-level control mechanism, they are harmful, because they make it much harder for programmers to form a mental model of the running process (keeping track, in your mind, what happens when you run the program).

That is at least my understanding of the main point in the famous goto considered harmful paper.

Re: The RedirectException

2008-04-07 10:14 • by OJ (unregistered)
188388 in reply to 188381
FredSaw:
Back in the pre-dotnet days I worked at a company which used VB as our development language. Its only built-in error trapping was by means of "On Error Goto [label]".


Well, there was also "On Error Resume Next". I have seen code that actually used it. It was awful.

Re: The RedirectException

2008-04-07 10:19 • by Rabiator (unregistered)
188390 in reply to 188352
Woohoo:
ouch...

you see the same form of abuse in Java a lot: using exceptions for flow control...
<snip>
The developer's worst sins in ascending cruelty:

1) creating a much too long method body (the whole system was certainly not OO)
2) not knowing about the "throw" statement and using a dumb deliberate error condition to force an exception
3) using an empty "catch" block with a generic exception type, thus rendering all real exception handling completely moot in this method
4) not knowing about the "return" statement (!!!)

number 4 is the real killer, of course... ;o)

I've seen the equivalent of 3) some years ago on a Delphi project I had taken over. In that case, it actually masked a few other errors in the code that SHOULD have thrown exceptions. As a result, the application proceeded with wrong and/or incomplete intermediate results.

I'd like to note, however, that the guy who wrote it was not a programmer by training. He had to help out in software development anyway, with not so bright results.

Re: The RedirectException

2008-04-07 10:21 • by OzPeter
188391 in reply to 188381
FredSaw:
Back in the pre-dotnet days I worked at a company which used VB as our development language. Its only built-in error trapping was by means of "On Error Goto [label]".On Error Goto Hell


In the dotnet days now I sometimes work in an environment that uses VBScript, which is not VB. In VBScript your only means of handling errors is "On Error Resume Next", we don't even have the luxury of "On Error Goto".

And yes I also had to invent a time machine in order to get to work 10 hours before I got up in the morning after spending 14 hours walking up hill each way in a snow storm

Re: The RedirectException

2008-04-07 10:24 • by xtremezone
NiceWTF:
As an implementation mechanism (where programmers don't have to look at them), goto's are fine. As a high-level control mechanism, they are harmful, because they make it much harder for programmers to form a mental model of the running process (keeping track, in your mind, what happens when you run the program).

That is at least my understanding of the main point in the famous goto considered harmful paper.
There are times where goto is the cleanest, most efficient, and best solution to a coding structure. They are relatively rare though. Saying that goto is only useful under the surface is just as bad as using goto when other control mechanisms should be used.
OJ:
Well, there was also "On Error Resume Next". I have seen code that actually used it. It was awful.
I think he's referring to actual VB (VB6, perhaps) wheras (AFAIK) On Error GoTo Next is a VBScript hack to ignore errors and allow the programmer to decide what to do by checking for errors manually (i.e. If Err.Number <> 0 Then). Or, if he so choses, let the script run ignoring the error and hope nothing bad happens. ::)

Addendum (2008-04-07 11:20):
Ahh, I meant On Error Resume Next. :-X To indicate that you want VBScript to again halt execution on an error you would then use On Error Goto 0. I clearly mixed them up...

I've found a few instances where it is necessary to use this construct in VBScript, but I generally wrap it in a function and signal errors with return values so they can be handled gracefully. I also make sure to re-enable script halting at the end of the function...

Re: The RedirectException

2008-04-07 10:40 • by OJ (unregistered)
188399 in reply to 188392
[quote user="xtremezone"][quote user="NiceWTF"]
[quote user="OJ"]Well, there was also "On Error Resume Next". I have seen code that actually used it. It was awful.[/quote]I think he's referring to actual VB (VB6, perhaps) wheras (AFAIK) On Error GoTo Next is a VBScript hack to ignore errors and allow the programmer to decide what to do by checking for errors manually (i.e. If Err.Number <> 0 Then). Or, if he so choses, let the script run ignoring the error and hope nothing bad happens. ::)[/quote]

If I am not entirely mistaken, QBasic and VBs at least up to 4 had both On Error Goto and On Error Resume Next. There were people who actually chose Resume Next (well, I did too when I dabbled in QBasic but I was maybe 14 at the time).

Re: The RedirectException

2008-04-07 10:53 • by alegr
188405 in reply to 188374
Waffle:
OzPeter:

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


If you're interested, I heard of a recent vacancy for that very profile.


Chariot-running experience required for that position.

Re: The RedirectException

2008-04-07 10:57 • by FredSaw
188406 in reply to 188391
OzPeter:
And yes I also had to invent a time machine in order to get to work 10 hours before I got up in the morning after spending 14 hours walking up hill each way in a snow storm
Lol--yeah, I walked that hill, too. :)

I didn't always read On Error Goto Hell as the instruction, "go to hell". Sometimes in my mind it read the same way as the famous "dll hell" phrase that was so overused during the fanfare heralding .Net: "Goto hell".

Re: The RedirectException

2008-04-07 11:01 • by paratus (unregistered)
188407 in reply to 188371
fred:
I hate to say it but I have been tempted by this before.
Go. Find. Another. Job.

Seriously. You're not fit to be a programmer.


That is a stupid thing to say. Making errors is the mark of good programmers, if you are willing to learn from them.

I am probably a better programmer than you are, but I have been tempted by this, and actually used it once in some form of it in a project. It did seem the easiest solution (it was for reading a file, and I generated an EndOfFile exception at the end). It was a stupid idea, but it did work and was easy to implement. Of course, the drawback is in maintenance/evolution, and I ended up rewriting it sanely a few years later (a 15 minutes job).

So, I think it is natural to be tempted by it, and programmers are quite good at persuading themselves that the first idea that crosses their mind is the correct one ("well, that situation [end-of-file, or redirection] is exceptional, so it make sense to use an exception for it, so I don't clutter the normal code path with code that handles that specific case"). It takes experience to understand why it is such a bad idea, and experience only comes with errors.

Btw, I think the CS courses should teach maintenance, as that is 80% of the work of a programmer (and in the other 20%, when you write new code, you actually have to think about maintenance, by you or others). Something like asking students to make modifications to code with design flaws, so they could learn the hard way why some ideas are bad.


That was actually one of the first things we did on my university on our first c++ course. We got a few programs that either didnt work properly, or not at all, with the job of finding the errors in them. It was the hardest part of that whole course, but you learned a fair bit about pointer errors when digging around unknown code for a REALLY weird error (and with c++, weird errors can be really weird errors). Especially if you havent been programming much previously and the teacher is a code structure nazi (and for that I thank him immensely).

Re: The RedirectException

2008-04-07 11:08 • by Joe Scylla (unregistered)
188411 in reply to 188384
NiceWTF:
...snipped...

That is at least my understanding of the main point in the famous goto considered harmful paper.


Some people also raise their voice for goto:
Code Complete 16.1 Using gotos
An Argument for the Use of goto Statements

imho the best summary about the use of goto:

Use of gotos is a matter of religion. My dogma is that in modern languages, you can easily replace nine out of ten gotos with equivalent structured constructs. In these simple cases, you should replace gotos out of habit. In the hard cases, you can still exorcise the goto in nine out of ten cases. In these cases, you can break the code into smaller routines; use nested ifs; test and retest a status variable; or restructure a conditional. Eliminating the goto is harder in these cases, but it's good mental exercise, and the techniques discussed in this section give you the tools to do it.

In the remaining one case out of 100 in which a goto is a legitimate solution to the problem, document it clearly and use it.


Re: The RedirectException

2008-04-07 11:13 • by ZippoLag
so.. basically the whole app wa one big exception handler, maybe the most complex one ever.-

Re: The RedirectException

2008-04-07 11:20 • by Steve (unregistered)
188414 in reply to 188352
Woohoo:

4) not knowing about the "return" statement (!!!)

number 4 is the real killer, of course... ;o)
There are some schools of thought which abjure the use of
return
statements other than as the last line of a function or method.

Re: The RedirectException

2008-04-07 11:21 • by haslo (unregistered)
I was forced to work with VBA only a few months back. And I did use "On Error GoTo", because there's no other way, and "On Error Resume Next" complete with checking for the value of the "Err" variable.

I did include more comments than code in that segment though, most of it was ranting about how much VBA's error handling sucks.

Re: The RedirectException

2008-04-07 11:30 • by GOTOs just help (unregistered)
188422 in reply to 188365
Matt:
OzPeter:
Joe Scylla:
Well, goto got stigmatized and now many are using Exceptions for flow control (and sometimes write better readable code).

Goto wasn't that bad.


What I find ironic is the the aboslute belief that Goto's are bad, yet when you get down to the bare metal thats fundementally what a CPU runs on.

Like all things Goto's are a tool, and its the misuse of the tool that is bad, not the tool itself (damn am I starting to sound like an NRA spokesperson???)


GOTOs don't kill applications- Programmers kill applications.


Guns don't kill people- People kill peoble --> guns just help

Re: The RedirectException

2008-04-07 11:31 • by FIA (unregistered)
188424 in reply to 188391
OzPeter:

And yes I also had to invent a time machine in order to get to work 10 hours before I got up in the morning after spending 14 hours walking up hill each way in a snow storm


Invent a time machine? That's nothing. Back in my day we 'ad to invent time itself, which we'd 'ewn from the primordial soup, and come up with a supporting mathmatical model (with equations) to explain it 't pit owner, that's before 47 'our walk home on our bare hand, at which point father'd declare us an imaginary construct and we'd cease to exist; and be bloody glad of it too.

Re: The RedirectException

2008-04-07 11:36 • by FredSaw
188426 in reply to 188412
ZippoLag:
so.. basically the whole app wa one big exception handler, maybe the most complex one ever.-
A clbuttic case of the exception becoming the rule.

Re: The RedirectException

2008-04-07 11:36 • by Bosshog (unregistered)
188428 in reply to 188362
ubersoldat:
Why? My Eyes!!! But... why? Please, go find the person who did this and ask him/her in wtf he was thinking of. Now my mind hurts. There goes my Monday productivity.

hmmmm... Firefox spell checker thinks that monday should be Monday only.


Sounds like a case of the Mondays.

Re: The RedirectException

2008-04-07 11:39 • by ObiWayneKenobi
188430 in reply to 188388
OJ:

Well, there was also "On Error Resume Next". I have seen code that actually used it. It was awful.


"Awful" is putting it lightly. Try maintaining code that *relies* on it to even work, because the code calls methods on objects prior to creating them, and references nonexistent methods/properties from include files six levels deep.

Re: The RedirectException

2008-04-07 11:50 • by Flash
I had a professor who announced that GOTO statements were okay. The class was aghast! Then he said that labels were evil. He had a point. When you come across a GOTO statement, you know exactly what it's going to do. It's unconditional...no thinking or interpretation required. However, when you see a label in the code, you don't know where it's being called or from how many places or for what reasons. (Well, not without a lot of effort.)

The net effect of his advice matched that of Dijkstra: no labels, so no GOTOs. We breathed sighs of relief.

Re: The RedirectException

2008-04-07 12:43 • by Heck (unregistered)
188447 in reply to 188411
Joe Scylla:

Some people also raise their voice for goto:
Code Complete 16.1 Using gotos
An Argument for the Use of goto Statements

To summarize:

- Goto code can be hard to translate into Goto-less code. What does that say about the readability of Goto code?
- Goto is good for handling errors. However, neither of those two links show exception handling in any form.
- Goto is good to avoid duplicate code... Except it's trivial to wrap the duplicate code in a new function.

The error handling bit is interesting to me... I suspect that any case for which Goto is still useful is likely a case that would be better turned into a "goto in disguise", like exception handling, continue/break in loops, return, etc. While they may be effectively little more than goto, they're generally much more readable, and they give the compiler more information, which is always a good thing.

For example: Exception handling, in its simplest form, is a goto. But it will also unroll the stack, firing off destructors along the way, and it will only jump farther up the call stack, not to some completely random label somewhere in the code. It is thus more structured than Goto, and designed to replace a specific use of goto.

If we're really down to only one case out of 100 in which goto is a legitimate solution, we can't be very many syntactical hacks away from removing it entirely.

Re: The RedirectException

2008-04-07 12:54 • by operagost
188450 in reply to 188362
ubersoldat:
Why? My Eyes!!! But... why? Please, go find the person who did this and ask him/her in wtf he was thinking of. Now my mind hurts. There goes my Monday productivity.

hmmmm... Firefox spell checker thinks that monday should be Monday only.

It is capitalized in American English.

Re: The RedirectException

2008-04-07 13:03 • by operagost
188455 in reply to 188378
Martin Dreier:
OzPeter:
[...](damn am I starting to sound like an NRA spokesperson???)


They have a vacancy for one.

SCNR.

He retired five years ago when he was diagnosed with Alzheimer's.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment