- 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
In one large product I worked on, there was one goto statement. Instead of a trivial for-loop someone thought using "goto" would be quicker. We added a comment to please leave it there is an example of human stupidity.
Admin
Let's see the positive side: if ever the else keyword gets deprecated in the future, than at least they're prepared.
Admin
You can do better than this, really:
I mean, skipping was there before branching was even a thing, historically… ;-)
Admin
BTW, this should really be
instead of
pre > code { overflow-x: scroll; }
Just saying. (Traditional coda to any critical comment.)
Admin
In theory, you could get rid of this obnoxiousness by writing a simple parsing program (the goto token inside an if statement is a bit of a giveaway) and just substituting via a template.
In practice, I wouldn't bother. It's obnoxious, but it works.
Admin
If this is C++ and their pseudo-else block contains any variable declarations with initializers or non-trivial constructors, they'd get a compiler error about the goto jumping past initialization too.
Admin
Not really true. Skipping is branching.
However, writing high-level code as if it were assembler (skipping) seems to me to ignore the benefits of writing high-level code.
(Leaving the dubious benefits of the common "single point of exit" pattern and the even more dubious benefits of a longjmp, of course.)
Admin
When you come to an else, you must skip it! Skip it good!
Admin
Well some of us still do it like that (at least when I'm using my home build 8-bit computer) :-)
And when you think of it, the actual machine-code generated by the compiler will look like that as at the machine level there is only jump (aka goto) and conditional jump
Admin
Sometimes, you want the 'else' part early/first, since it is very short (as in, 'Die. Die now.') and the actual if is many lines of babble.
Admin
I thought this was familiar:
https://thedailywtf.com/articles/When_A_Problem_Comes_Along,_You_Must_skipit
Admin
That looks like the coding style used all over OpenSSL's crypto code, all error handling is 'goto err' which is actually the normal exit except it skips some cleanup and assumes some status code set at the start of the function still indicates failure at the point when it returns.
Admin
I can recall writing code in the 1970s in languages that did not have an else clause as part of their if statement. I hope this code doesn't date from then. But it might.
I'm not sure which is more horrifying: the idea this stuff might be (multi-ported) legacy from then, or this stuff might be more current stuff written by clueless morons. Either scenario is a disaster. Just different kinds of disaster.
Admin
More likely the original coder dates from then, and hasn't learned any new tricks like this fancy fandangled "else clause" in the decades since.
Admin
"to at least keep the codebase consistent" is a very something way of saying "so the previous dude has no excuse not to touch the code anymore". Been there, seen that.
Admin
Some folks seem to imply the authors of such code are either stupid or morons. I respectfully disagree. This is textbook psychopath.
I'm also sadly reminded this is a common pattern in DOS CMD/BAT files. And unfortunately I still get to write some of these from time to time.
Admin
It made me feel really ancient when, in the course of a house clearance, I found a Fortran-77 course handout from my undergraduate days containing the earnest advice: "Don't nest [those new-fangled] block-IFs more than three deep; use an occasional GOTO if necessary".
Ralf: If Bourne shell scripting is like trying to play the piano in boxing gloves; DOS BAT scripting is like trying to play the piano in boxing gloves from inside a straitjacket.
Admin
"too many just followed the patterns that were already there."
Decisions"
I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....
Admin
"too many just followed the patterns that were already there."
Decisions"
I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....
Admin
"too many just followed the patterns that were already there."
Decisions"
I try to avoid #3 like the plague. There is often restrictions placed by management inhibiting #2, so #1 actually becomes the best....
Admin
We heard you the first time. :) Just kidding.
Agree completely. BTDT. Though I'd rephrase that slightly as "... so #1 actually becomes the least bad choice."
Admin
The first assembly language I learned was the DEC PDP-10. It includes a sheaf of instructions that conditionally skip the following instruction, such as "Add One and Skip if Less than or Equal to zero". This works because all instructions are the same length: one 36-bit word.
Admin
Looks like their programmer tried to code as FORTRAN IV (66). It only had an IF but no else, at least on HP3000 You simulated else with GOTO's
Admin
Gloriously turing-complete