- 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
I just got terrible Excel flashbacks of functions with endless =IF(something;"OK";IF(something;"LESS OK";IF(something;"HELP SOS";IF(something;"NO WAIT IT'S OK";IF(etc...
And yes I know I was using Excel for something it was not really meant for but it was the only programming tool available (read: allowed) at the time.
Admin
Damn, waited for years to write "First"... Went to check my else if branch code for bugs
Admin
anything can be frist
Admin
TRWTF is the happy ending. Bad developer gets fired?
Since this is in a safety critical industry, I feel better about airplanes and self driving cars already.
CAPTCHA: ague - what I get from some of these stories
Admin
Some coding standards (like, say, the ones used for C++ on the US Joint Strike Fighter program) specifically require an if/else if chain to be terminated with either an "else" handler or a comment that explains why there is no else. That seems like good practice for any software with significant safety implications.
Admin
Admin
// DO NOT make changes below this comment
if (frist) { doLameFristComment(); } else if (!frist) { doAnythingCanHappenComment("And probably will!"); }
Admin
If so, TRWTF is using a loosely typed run-time language like JavaScript or PHP that allow undefined variables... especially in life-critical apps.
Or, more likely, I've been mislead by Alex's brillant editing.
Admin
I think he means about when some variable is supposed to be assigned a different value in the 2 branches.
Admin
How about:
alert("Logic inconsistency error detected! After you click OK, this instance of the simulation will be terminated. You should awake in a similar universe where this never happened. In most cases people report no recollection of this event.\n\nOh by the way, if you tell anyone else, it makes timeline reintegration much more difficult. So don't do that.");
Admin
if patient.sick? && !patient.dead? heal patient else if !patient.sick? && !patient.dead? bury patient end
Admin
Wow the process worked.
Admin
Admin
You're right, anything could happen:
Admin
if patient.sick? && !patient.dead? heal patient else if !patient.sick? || patient.dead? if patient.dead? bury patient end end
FTFY
Admin
Admin
PS. 'brillant' is not a typo; you must be new here!
Admin
...into this:
What happens if a is 10?
Admin
Decades of experience in waiting to be frist
Admin
if (a) { dowork(); } else if (!a) { domorework(); } else { return(FILE_NOT_FOUND); }
Admin
But that doesn't help me understand "creating code paths that did not assign these variables".
Admin
shouldn't it be ... else if !patient.sick? || patient.dead? ...
Admin
Admin
Admin
Admin
Admin
An example in c++ would be:
float x;
if (x > 10) {
}
Defining x without initialising it to something (eg = 5.4f) means that it'll just contain the value of whatever was as that memory location. Could be any number, and results can change every time you run it.
Admin
Seeing a marginal WTF, expects great reams of meta commentary on the post about the failure. Meta commentary does not exisist.
So fail
Admin
Admin
I took that to mean that using this if - else if style would complicate things further up.
"Doug was a go-getter. He made the effort to go through the rest of the module and bring all the if/else statements into his if/else if "pattern"."
So essentially using this style, he introduced bugs higher up in the code that trickled down to cause a RWTF issue in this code.
Admin
Because if you convert if .. else, into if .. else if !(cond) and you screw up the !(cond) part suddenly you have code where neither the if clause nor the else clause gets executed where it would have alsways been the case at least one would have been run before.
Admin
Something like that spells it out enough for you?
Admin
Fix...
Admin
Elseif can be useful. But it can ended in a mess
Admin
Admin
Works fine in Oracle pl/sql:
DECLARE a BOOLEAN; BEGIN IF ( a ) THEN DBMS_OUTPUT.PUT_LINE( 'true' ); ELSIF ( not a ) THEN DBMS_OUTPUT.PUT_LINE( 'false' ); ELSE DBMS_OUTPUT.PUT_LINE( 'null=> other universe?' ); END IF; END;
Output: 'null=> other universe?'
Admin
Admin
Is doing nothing when a== 0, b >= 30 and c != null intentional? If not it somehow proves the point...
Admin
the correct construct is of course to first create a boolean of the condition.
Admin
Reminds me of another "experienced" developer, who'd always use the mouse to select items and then do copy&paste through the context menu. Another one of those valued developers with over a decade of experience ...
Admin
FTFY
Admin
Admin
if(i++ == 1){ doSomething(); }else if(i++ == 1){ doSomethingElse(); }
Admin
It's probably late for this, but...
The real problem with
if (condition) {...} elsif (reverse_of_condition) {...} end
Is not that YOU might mess up your reverse_of_condition computation. We can assume that YOU are smart enough to use !(condition) for that. The real problem is that at some point condition will need to be modified. By someone who has never seen this code before. Who isn't as smart as you.
That's what "doubled the complexity" meant.
Admin
Admin
IIRC it's the ANSI standard: null != null. Its the same in T-SQL (SQL Server) by default. One hell of an annoying convention.
Admin
TRWTF is that he had decades of experience in VB
Admin
Now you're exaggerating a little. If you had said, a guy scrolls up 2 pages of text to copy a short word so that he can paste it where he was below (to avoid typing it), then I'd understand. I noticed a couple of devs doing that for as little as 4-characters. Not to mention that IDE at the time was Visual Studio, where intellisense is present.
Admin
HAHAHAAHAHHAA
Admin