- 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
Optimizing your code, with a few bug fixes:
// No matter what, bury the patient first... if ((patient.sick || !patient.sick) && (patient.dead || !patient.dead)) buryPatient(); } else if ((!patient.sick && patient.sick) || (!patient.dead && patient.dead)) { // If we get here, the patient is God, lets heal him! healPatient(); }
// It's ZOMBIE time! doCreateZombieFromPatient();
Admin
How do you pronounce "ague"? "A jew" or "ag you" or "a goo" or "a gua" or ? Different pictures pop into my head depending on how it's pronounced :P
Admin
Where's the damn ponies?
Admin
What I don't understand is, how can anybody who knows enough about programming to even make this mistake correctly not understand the problem with this type of logic? In all seriousness, WTF was he thinking, and why was he continuing to think it?
Admin
blah
Admin
404 Error: Correct Pronunciation Not Found.
Admin
Here's how people like Doug happen:
An engineer teaches himself to program, probably in VB. He cobbles together a project that becomes very valuable to his organization. He works in a bubble; others may glimpse the code once in a while, but they're too busy with their own work to improve on the code. They may make recommendations, but Doug scoffs at the elitist attitude of "professional" programmers.
"Why size arrays correctly when modern machines have practically infinite memory? Just make it as big as possible!"
"Source versioning? Every change I make improves the code, so why keep the old versions? Besides, I know what changes I've made."
"I'm getting nanosecond response time. See, these floats tell me so."
"VB6 isn't multithreaded? Ha! It is in my code."
Anyway, years of honing one piece of code and inertia imbue Doug with a false sense of understanding and confidence. He really thinks he knows what he's doing; in fact he thinks he knows better than everyone else. Hence, Doug.
Yes, I could submit a week's worth of TDWTFs about the Doug I knew.
Admin
It's not the Doug you know that gets you. It's the Doug you don't know.
Admin
You can't know if two unknown things are the same as each other, thus NULL != NULL. To check for NULL you use the 'IS NULL' test instead.
Admin
that was the point indeed :)
Admin
captcha: causa
Admin
More obviously, defining a fact (or piece of logic) in more than one location ensures things will go wrong down the track.
Admin
Admin
Doug wasn't smart enough to complement the whole condition:
He tried to complement each inequality instead, and screwed it up even before anyone came by and modified it.
Admin
if (a) do_something(); else if (b) do_something_else(); else assert(false); // should never get here
The asserts do get compiled out in a release build, but are very good at finding things exactly like uninitialized variables.
Admin
Admin
Admin
If a given SQL engine correctly and fully implements NULL, then all normal predicates (= <> > <) return false if either or both test values are NULL. To test for NULL, you have to use "x IS NULL" or "ISNULL(x)" depending on the engine.
If "a" is NULL in Rob's example then neither "if" would be true.
Admin
Admin
Forgive me if this has already been mentioned, but if the intention is to have an else if contain an inverse condition to the if (that is, catch anything that the if does not catch), and the else if does not execute due to a logical error, then an important branch of code may be unexpectedly missed (by the developer) due to someone's stubborn refusal to use an else.
Admin
A wise person once described this idea to me as: "some people with twenty years of experience really have twenty years of experience; some people with twenty years of experience just have one year of experience, twenty times."
Admin
FTFY
Admin
Admin
Admin
Simply put: he's a dumbass - who managed somehow to bullshit his way around jobs enough years to think of himself as someone with experience - but, in reality, he's a dumbass (and he's not the only one; no pun intended).
Admin
That logic is dumb, as is who imposed it on you, as are you who accepts it. Reading that tears my head. If my employer made my type that, I would quit. I my employee typed that, I would fire them. I don't care if you're coding a blog or software to control jets - it's dumb, and it doesn't make sense.
Admin
Admin
So, TRWTF is that the correct thing happened and it's still being shown on this website?
Admin
No, you're dumb, for not specifying what part doesn't make sense. There are several concepts in the post you quoted and several of them do make sense and are not dumb. For instance, the main concept is that all control paths must be covered, which is not a dumb thing to require. So, because we can assume that you're calling that dumb logic, we must assume that you are the dumb one. QED
Admin
// test flying object (fo) type... if(fo.hasBeak) return "It's a bird!" else if (fo.hasWings) return "It's a plane!" else assert(false) // Superman ain't real!
Admin
Yes, that's standard SQL. And yes, very poorly thought out... resulting in expressions like (x = y or (x is null and y is null)) scattered throughout the system... and as often than not, someone has the conditions wrong.
Admin
It's not dumb - it's just paranoid. And sometimes, that kind of paranoia is a really good idea - if something should never happen, don't just assume that it never will.
Admin
TRWTF is that he got hired in the first place.
Admin
FRIST!!! I did it - FINALLY!
Admin
For cases including 'c' 'd' 'e' and 'f', i would agree, but when one has just two statements, would it not be more prudent to do assert(b) in the else clause together with do_something_else(); rather then to create the third clause to assert false?
Admin
Admin
I disagree to some extent. NULL to me means "known to be invalid", not "unknown". Something logically can be valid but unknown given the context. If two things are known to be invalid they can logically be considered equivalent.
Admin
Admin
Admin
All of
Admin
It's kind of the same concept. NULL is nothing - it's not specific (it's not really quantifiable - it's not even 0 - having none of something is not the same as having nothing (none of everythiong))). You can't compare two nothings and decide they're the same, bnecause they're, well nothing. Infinity is massviely big and not specific.
I'm goin for a panadlol
Admin
if (++a == 0) { a = a + 1; } else if (++a != 0) { a = a + 2; }
Admin
I'll just go back under my bridge now.
Admin
Admin
Admin
And then there's:
Admin
I'd rather see the plane tell the pilot "Keep your eyes open and talk to traffic control now because I'm going to spend the next 5 minutes rebooting" instead of "resume next and crash".
Admin
Admin
If the programmer remembers they want to use the same variable that was used two screenfuls of code earlier, but doesn't remember what it was called, which letter should they type in order to get Intellisense to give them a list of reasonable candidates?
Well anyway, you'd make a good manager, with typical inability to distinguish which of your subordinates are competent and which aren't. You'd discover pretty quickly which ones have no social skills, but you won't understand why, and you'll fire them immediately.
Admin