- 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
its always a good idea to check everythign a few times before you process any data.... gag
First Post!
Admin
WTF?... I mean... I've heard of defensive programming, but this it just too much.....
Admin
The only thing I can think of is that there were concurrency issues, and the original coder thought this would be a workable solution. After all, if the value remains unchanged after three whole tests, surely any possible race conditions have been thwarted!
Jason.
Admin
Their boss probably told them to "measure twice, cut once", and they took it too much to heart.
Admin
paid by the line anyone?
even if he wanted to do this, he could 've refactored it to a function tripleCheck()
Admin
I agree about concurrency.
It depends on the compiler, but the extra checks might well be optimised away.
Sincerely,
Gene Wirchenko
Admin
Is it me, or does this look like autogenerated code?
Even still I can't understand anyone reading that and not thinking 'That's silly'.
Question: Wouldn't whichever compiler/interpreter this was written for not optimise and remove the duplicate tests? That would mean it doesn't even work in the 'avoid race conditions' explanation.
Admin
Ah! Snap!
Admin
For the sake of his users, I hope so...
Admin
Excellent idea!
With thrice as much error checking, it must be foolproof.
Admin
I agree Mark. That's definately a bug in an autogen tool. That's why we always proof read autogened code, right?
Admin
Looks to me like this could be protection from race conditions by someone who doesn't really grep threaded programming.
...but if you're going to do that like this, you need to put time delays between each check. Otherwise there's not much point in the repeated checks.
Just stick some
{ short i; while(i >= 0) i++; }
blocks in there between the 1st & 2nd, and 2nd & 3rd, of each of the triple checks. WTF solved.(let's see who doesn't realise I'm kidding...)
Admin
This is why you shouldn't use copy-and-paste-paste-paste programming.
Admin
Obviously this was for a goverment job. He is just checking all three forms of the required triplicate format.
pi
Admin
Agreed--this was written by someone who doesn't know how to handle shared access to files. Locking mechanisms exist for a reason!
On the other hand, I've writtten code not too different when dealing with stupid hardware. No sharing issues, just slow to respond. By checking multiple times you could ensure that it wasn't just about ready to tell you no. A delay would have accomplished the same thing but getting a delay loop that behaved on CPU's of widely different speeds would be a problem but by hitting the offending hardware you got a much more predictable delay.
Admin
seems to me the guy heard something about race conditions... it's common to see duplicated code to try and prevent race conditions (which doesn't really help, but kinda makes you think it does)
Admin
Maybe the original programmer had obsessive compulsive disorder.
You know, like those guys who always have to turn the light on 3 times when they enter a room?
Admin
It brings a whole new meaning to 'ternary operator' doesn't it? [:P]
Admin
Rofl. Thanks, you made my day ;)
Admin
My first throught as well. Buggy auto code generation.
In fact, it reminds me of the way Frontpage used to generate HTML.....
Admin
But did anyone check the "is_active" method
function is_active bool ( return randomize(true|false); )
If you're lucky enough to get three trues in a row, the subroutine will run add{object}Row().
Maybe it's a random way to populate a set of tables.
Admin
Tsk, tsk, tsk.Fresh out college and already so drunk on the job, he's seeing in triplets...
Admin
All this talk about race conditions on the day after MLK day... coincidence?
Admin
Now, the first post about preventing concurrency problems made me chuckle, but after having read that 'explanation' for the fourth time I feel that some people don't just mean sarcasm.
How exactly does this WTF prevent race conditions? If the variable can be messed with in between being checked and being altered, then it can as well be messed with between being checked for the third time and being altered.
Please enlighten me if there is actually any point in this WTF that I miss.
Admin
The creator of that code was probably dealing with the highly skilled assassin Mustafa. Austin Powers, anyone?
Admin
My vote is for bad autogen code as well. Even the best code generation systems end up with some WTFs like these from time to time.
Admin
It's obvious to me what's going on here. The programmer did it like this for a year or two. Then all of a sudden he switched to only doing one check. Why, you ask? So that he could say that he tripled his productivity when annual performance reviews came up! Brillant!
Admin
I'm curious to know what the hell he is doing casting
I tried really hard to come up with an explanation as to why he checked everything three times but I just can't figure it out.
I don't buy the BS (I'm also not sure if people are kidding or not) about concurrency.
Seriously, do you think that someone who writes code like this has heard about concurrency issues?
It's amazing the guy has a job at all!
Admin
What the hell is wrong with you? Stop signing your posts.
Sincerely,
Humbly,
With Love,
Regards,
hahanoob
Admin
he needs a fourth check
we all know bad things happen in 3's
Admin
It doesn't prevent race conditions. What people are saying is that to certain, less-skilled programmers, it may appear to prevent race conditions, but in reality it does not.
Coincidentally, I notice that the Size and Font dropdown lists above the reply area default to "3" and "Times" ;).
Admin
Where's the specs ?
Admin
So WTF did he replace it with? It'd be much better to scoff at the existing code if it was successfully replaced with something better. Otherwise, the WTF'er is still clueless as to WTF the problem is that caused the original coder to do three checks in the first place.
Admin
Obviously from the Lewis Carroll school of programming:
"I told you once,
I've told you twice,
I've said it to you three times,
and what I tell you three times is true."
Lewis Carrol, the Hunting of the Snark.
Admin
I'd say I agree with you, but you know what they say about arguing on the internet....
Admin
Probably some really ghetto and stupid way to be thread safe.
Admin
He's actually casting dr[], which is another wtf, using a boolean for accessing an array.
Admin
bad! Bad code generating bot!!!!
Looks like the result of a flakey uml to code generator or something equally demented. The matrix and asimov talk about when computers and programs get so complicated only other computers can write them. Bah, I say. If it's screwed up in the first generation, progressive generations will look more and more like the cast from deliverance.
Computers hillbillies would regret ever having us write the first generation but be too stupid to fix the problem.
Garbage in, garbage out as they say.
That said, if you're gotta let something generate code for you, at least check that it produces something reasonable. I've been told about java code where each level of inheritance only added a single property/method. Stupidity of that degree is too time consuming to be anything BUT the result of a computer output from modeling software.
Admin
You can count my vote to the autogen-theory.
I mean seriously, no one is as stupid as to write that by hand or even copy&paste, as for accesing an array with a boolean; think again, who said is_active is a boolean?
Admin
Oh and let me laugh at the CAPTCHA.
I had the word to type in AutoComplete, and I've posted 10 posts maximum.
Admin
pfft. The real wtf is the complete lack of error handling:
<font size="3">bool unthinkableMayhem = invert_bool(true);
</font>
Admin
I'm suprised no one said much about the []'s. He could have overloaded them to mean anything. Also, you don't know what dr is, only that it has DataRows. Maybe accessing it one time will cause something to happen, the second is a retry, and if it doesn't work by the third then just forget it.
Even if this is the case, still a real stupid way to go about it.
Admin
No way. You're all giving him way too much credit. This guy thinks thread safe means "without needles".
More likely the boss announced that productivity will be measured in lines of code and nothing more.
Admin
I think there is another explanation that hasnt been tossed out there ...
is it possible this code was corrupted by some revision control system, someone applying some patches that happened to get applied 3 times?
Admin
I've seen production code like this at my previous project. For some reason one developer thought that executing certain SLQ update statement (in Access VBA [:^)] ) couple of times, as opposed to just once, really really updates. So some not all updates statement were wrapped in for loop. I am not sure what criteria this developer used to determine which updates qualified for that. Frankly, I was afraid to ask [:)]
Admin
I see a future where seintient AI programs clutered with WTF's search the internet for rogue programmers that will put them out of their misery.
Admin
That was my first thought too. But for sure a bad generator.
Admin
Looks to me like this could be written by someone who doesn't really grok the difference between "grep" and "grok".
Admin
My guess is that the code at one time checked three different things. Perhaps the same field in the different instances or something. And a design change got made and someone went through and mechanically changed all references to one instance another and ended up with three checks that were excactly the same. But the person was just doing mindless replacement and didn't notice and so didn't bother to collect them together.
Admin
What if the == operator was overloaded to have side effects?