- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
This is a case of malicious misquoting. The original author did say that he decided against it.
Admin
Ummm... No. Sorry. Have to disagree.
I've been writing code professionally for more than 20 years, and as a hobby for several years prior to that. I can count the number of times I typed GOTO easily. Once, in the sentence before this one. I code now in Delphi, but have used several other languages along the way, and never had to clutter my code with that kruft.
Admin
I write gotos. I use them like EXIT statements to get out of loops. I never, ever use them to branch into a loop.
Admin
You're being too literal with your interpretation of expecting.
Using an exception for something you know may happen, but shouldn't in normal cases, is appropriate. As you said, using them for flow control is always wrong. I guess we meant the same thing, but obviously your phrasing was much better than mine. :-)
My point was that, if they were for handling normal branching in the code, they wouldn't have been called "exceptions"; instead they'd have been called "NormalOps", or "CodeBranch" or something.
I'd agree 100% with everything else you said as well.
Admin
My guess is that the try block exists for the sole purpose of throwing the RedirectException in it.
Admin
Have you ever used a switch statement? Essentially a fancy set of if/then statements with GOTOs.
Admin
There's no such thing as a "read-only variable". A "read-only variable" doesn't exist. If you can't change it, it's a constant. If you can change it, it's a variable. Be fed up all you like - you shouldn't use read-only variables, because they don't exist.
And, as I explained above, you're wrong. It's not a variable by definition if you can't change it's value. It's a constant. Calling it a variable is like calling a car a table; they're not the same thing at all, and referring to them as the same thing is simply wrong.
Look at the reality of the situation, and not your imaginary idea of the way things are. A constant is not a variable, a variable is not a constant, and an exception is not a flow control mechanism.
Seriously, if you can't understand the difference, you should find another line of work.
Admin
And apparently talking to yourself, as we have no idea who else you'd be referencing. Perhaps you should see someone about those voices in your head? :-)
Admin
Remember that C does not have exceptions. An alternative would be like:
This gets tedious real quick. Another thing you can do is to just let the ifs nest as far as needed, but that doesn't make the code very clear.
I think that the use of goto as described by Gordon is a good replacement for exceptions in languages that don't have them.
Admin
A lot of you, even the ones who deal with something lower level such as C/C++ probably never have been put into a situation where using a goto did the bad things you were supposed to avoid.
When doing your for loops or if statements, it tends to get translated into a 'jnz' or 'jz' instructions. These are short jumps and usually don't cause what is called a 'branch penalty', where the CPU read-ahead cache is flushed. A goto however, unless short in scope and optimized properly by the compiler, can very well jump outside of the bounds of the cache, causing a branch penalty usually.
Today, caches are bigger, and optimizers are better, and cpus/ram are faster. You can use a goto without the blaring performance hits of yesterday.
The issue comes along though, that some of you may not always be writing code that targets an x86. I learned all about this stuff when I was thrown knee deep into having to program a 68000 based phone switch microcontroller. Having good practices always is a better idea, rather than just saying "Meh. I'll never have to deal with that"
Admin
There you go. I even preserved the playback position overruns.
It's a matter of taste, but I think my version is clearer.
Admin
Wrong. Exceptions are supposed to be used rarely, to handle issues in the code that are not to normally occur. That's why they're called "exceptions".
Running to the end of file is not exceptional, but is not normally encountered, and therefore an exception is fine to handle that unusual (exceptional) condition. See? That's why they call them exceptions.
And not using exceptions inappropriately doesn't result in "hacky stupid code", unless you're a hacky stupid programmer. Using them where you shouldn't just adds overhead to your code, slows down execution of your application, and shows people you don't know what you're doing. Maybe that works for some people; it doesn't for me.
Admin
Ummm.... Have you ever coded directly in binary? Essentially a fancy set of if/then statements as well.
Your point is missing the whole concept of readability and maintainability, which goto impedes. Spaghetti code is the usual result of goto usage. Trying to justify it by comparing it to more maintainable and understandable code structures is like trying to justify coding directly in machine code because they eventually end up doing the same thing. The machine code isn't as maintainable or legible, which is why we don't code in it.
Admin
Yes, they do propogate up the stack quite nicely. In a fashion that quite resembles throwing a ball into an out-field full of blind players. Someone may catch it, but maybe the ball crashes to the ground.
Admin
This is essentially how CherryPy does things. It's acceptable to
in order to ask for a redirect. See the tutorial linked off of the official CherryPy site!http://genshi.edgewall.org/wiki/GenshiTutorial#AddingaSubmissionForm
Admin
On the other hand, just look how some highly illogical languages such as Perl need to jump through hoops if you want a constant in your program.
(In Perl, constants do not seem to be provided by the core language; you can use an extension module, which simulates constants by apparently setting up a function behind the scenes, which always returns the same value.)
I suppose it would be the same on a machine-language level; a constant is something somewhere in memory, so you could always overwrite that memory location if and when you feel like it...
So Iago may still be right, in a sense. That which we call exception by any other name is still just a bunch of zeroes and ones in some memory chip or one some hard disk... ;-)
Admin
As was mentioned several times before, like in the featured post I responded to.
Admin
If you do much programming in ASY, you use GOTO dirivatives alot!
Admin
GOTOs are evil because the principle of locality (on which all caches are based on ) fails when code jumps indiscrimantly.
Admin
Smells a lot like Enhydra's ServerPageRedirectException (http://kickjava.com/src/com/lutris/appserver/server/httpPresentation/ServerPageRedirectException.java.htm), which is even worse because it's actually part of the framework.
Admin
Once you've got into a few nested loop levels and your conditional logic is getting complicated, for the sake of readability its much better to use a goto with a properly named label (like end_of_outer_loop) to break out of it than to start playing with boolean algerbra hell and introducing loads of flags.
Admin
switch == GOTOs. WTF
Admin
There is no output. If you comment out the if and goto the program outputs...
Is that not what you said would cause the error(s)? O_o
Addendum (2008-04-09 13:34): Compiled with...
Admin
You are just so right...the constant ;o) misunderstanding/misuse of the term "constant" might stem from the fact, that not many (or at least not enough) developers know the term "literal".
Literals are commonly called "constants" by many people, which leads to
*) either not having a term left for "real" constants (i.e. "variable" declarations with some constant/final keyword), therefore resorting to dumb workarounds like "read-only variable"
*) or using the same term interchangeably for two very distinct concepts...
Go ahead and ask all the developers you can get hold of how they call constructs like
or
in code - I bet more than 50% will answer "Constants of course!".
Then ask those who did to name all parts in lines like
or
Wanna bet?
"Why, of course this is a read-only variable initialized with a constant!" ;o))
Admin
FYI, those schools of thought are wrong.
Admin
Those of you who are fanatically against Exceptions for non-exceptional things: What do you make of the python StopIteration exception?
It's used for iterators to signal the end of a sequence.
I find it very clean and easy to use. Just because Exceptions may have been invented for exceptional cases (although I even doubt that, since it's hard to define 'exceptional'), doesn't mean they can't be useful for other things.
Doesn't it all boil down to how useful and productive you get (counting maintenance, not just development, of course)?
Zealotry in all forms annoys me...
There may be good arguments against most uses of goto, but are there really good arguments for banning Exceptions except for error handling?
Admin
Sorry, but that is just plain wrong.
Yes, caches like 'locality', but the only way you could achieve that would be to have one long function which goes through from beginning to end, with only small loops in.
Once you make a function call, you're breaking 'locality' - probably far more than using a goto within the same function.
Gotos also don't break pipelining, since a 'goto' is an unconditional jump, so the pipeline fetcher can predict with 100% accuracy where it's going to go to and start pre-fetching from the correct place. A switch or if/then is far less predictable than a goto for a pipeliner.
In any case, if your choice is between 'goto' and an exception, and performance is your deciding factor (which it must be if you're talking about cache effects), then goto is a very clear winner! Exceptions can take thousands of times longer than a goto. A goto is a VERY fast operation.
The only reason not to use a goto within a function is readability. That's a strong enough reason, there don't need to be any others.
(As other people have said, lots of C++ operations are really 'gotos in disguise' so any cache/pipeliner disadvantages would hit those just as much).
Admin
The scope of the iterator is within the loop construct - the goto doesn't reach a place where the iterator is in scope, but hasn't been initialised.
So, no, it's not the same problem at all. Jumping into the for() loop, though ...
Admin
...which seems to avoid such an error.
Addendum (2008-04-10 15:19):
I would normally declare a for-loop control variable or iterator inside the for-loop's initializer, but I was demonstrating that by declaring the variable above the goto you seem to avoid the error mentioned earlier.
Admin
Computers use GOTOs. Programmers abuse them. The reason for this is that the computer has a nice, accurate data structure containing all the source/destination addresses, can follow the references instantly, and never blinks/mis-clicks/changes the source code. Humans, on the other hand, are lucky if they can remember what file they're currently editing, let alone being able to figure out the spaghetti code that some jerk who thinks he's as smart as the compiler wrote 5 years ago.
In short, don't use GOTOs, as the compiler is infinitely better at it than you.
Admin
Obviously this was the wrong time...
Admin
I found code I inherited at work that did Int32.Parse("abc") to do flow control (break out of a loop in that case). That's just one of the things that makes me cry here.
Admin
No, no, users kill applications.
Admin
Admin
The bottom line, as you say, is that anybody who uses a GOTO in anything other than tight OS kernel code is a dingbat. Arguments about breaks, continues, exits, etc etc are irrelevant to this. These keywords form part of a higher-level semantic; how they are implemented is irrelevant. GOTO is an assembler-level semantic (thus causing significant pain whilst unwinding stacks and freeing memory); and it's not even implemented as a GOTO in assembler, anyway. It's implemented as a "Jump Immediate."
Admin
If you've been getting those kind of errors after using Response.Redirect use this aproach:
Response.Redirect("somefile.aspx", true); HttpContext.Current.ApplicationInstance.CompleteRequest();
Admin
The reason not to do returns in the middle of code is that it increases the McCabe cyclomatic complexity. Cyclomatic complexity is a metric used in analyzing complexity and error-proneness of code. Most people have long forgotten the why of not doing the return in the middle of the code.
IMHO, the return in the middle of the code can make thing much simpler and less error prone in actuality even if it does increase the mathematical measures of complexity. If you return in the middle of the code, you don't have to ensure that you didn't accidentally execute other code (due to mistakes in tests before the return) before you actually return.
Admin
Admin
OOP though the comment might be, I see no difference between a "private method" and a Fortran function or procedure, so far as this argument goes. I'd suggest that this is a pretty reasonable representation of Dijkstra's opinions.
I'd imagine that "branching off to some other part of the code" is short-hand for "fighting the IDE to find the corresponding label, twenty-three pages down." I'd love to agree that this is "as hard to friggin read" as a call to DoLotsaCommonStuff(...), but, on the whole, I'd rather be in Philadelphia.
Admin
But spaghetti code is not so bad, just start pulling the strands and it will unravel. Macaroni code however is something else.
And no, this is not really a joke. Having refactored hundreds of programs, I can tell there really is such a difference.
M4
Admin
I have to quote my own WTF here from my MP3 player frontend:
And yes, it does do all sorts of nasty stuff, like catching EVERY exception... but hey, it works.
Admin
Elegant??? Do you understand what are you talking about??? Are you in the fashion vortex or are you trying to do your job creating programs that CAN (possibly) be maintained by other professionals like "you" (sigh...)
Admin
Well said!
Admin
Admin
This is a brilliant example of exception oriented programming, a very underused way of coding
Admin
GOTOs has some uses. They're rare. So what? GOTOs exist precisely because of them. For example escaping nested loops.
Admin
Upadłość Konsumencka Sanok Pomożemy Ci w złożeniu wniosku o upadłość i poprowadzimy Twoją sprawę kompetentnie i profesjonalnie.
Admin
Wow that was strange. I just wrote an really long comment but after I clicked submit my comment didn't show up. Grrrr... well I'm not writing all that over again. Anyway, just wanted to say fantastic blog! https://sites.google.com/view/kancelaria-upadlosc/home
Admin
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates. http://www.aotingmei.com/bbs/board.php?bo_table=free&wr_id=144838