- 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
Who, my first ever WTF on a WTF. How does IntToStr(DeliveryNumber) ever end up being an empty string if it's an integer? Or is that the WTF and I missed it? 8-<
Admin
Unfortunately this isn't all that uncommon. We have about 8000 users on our system and there are bugs and 'features' that should be replaced.
However over time the users have grown used to and found their own work arounds for the bugs (even our tech support people). They've grown so acustomed to working around the bugs that their fix has become a part of the functionality/usability of the system.
Any changes or improvements that disrupt their current work flow are usually not appreciated or prudent. The solution, prevention. Once a system is in place with humans are using it, making any changes is like pulling wisdom teeth.
Admin
Again... why are the quotation marks all screwy?
~JOSh-X
Admin
I'm certainly not defending this, though I don't really see the 'WTF-ness' of this code. I don't really know Delphi but IntToStr(int) should never return an empty string / char when it is a valid int, so that ShowMessage code should, theoratically, never run right?
Because, I assume that the deliverynumber should always be set in the application? Sure, that error doesn't look all too professional, but... oh well maybe I miss a point here :)
Admin
Oh wait, ok, I get it :)
if... if not....
Admin
I don't get it.
Admin
For those who don't get it: the then/else clauses are backwards.
Admin
IntToStr will never produce and empty string and throw an empty string and the clauses are backwards. It's a double whammy.
Admin
remove "and throw an empty string" from the above to convert to English. :D
Admin
For those who don't get it: WTF
Admin
OK, the code has a bug, IMO a bug like that (inverse logic in a branch statement) a lot of times is just a coder mistake when he was writing the condition. Where I'm those bugs are called "finger errors", although sometimes the brain (not the finger) seems to be the guilty one.
So yes, the snip has a bug... Is that bug a WTF?... (I couldn't resist asking)
Admin
I think the WTF is more in the fact that he couldn't change the code to fix a reaaaaally simple error, like changing it to IntToStr(DeliveryNumber) = '0' or something.
TPS Reports anyone?
Admin
@JoeJoe
I think you are correct. IntToStr shouln't ever return an empty string. The whole condition is a WTF no matter the inverse logic mistake. So I take back my question of the WTFness of this post.
Also... Why would he convert an integer to a string just to check it's value? I'm pretty sure checking DeliveryNumber > 0 or something like that would work.
Admin
Maybe I'm not as smart as you guys, but I really, REALLY don't get this one. It looks okay to me!
Admin
Hi everybody. (especially Dave) It's me, J. I'm baaaaack. ;-) LOL
Admin
Please J. This is a brand new WTF and you’re doing well so far. Don’t drag us through the hip-hop muck and grime again. I beg of you.
Admin
I have to confess that I missed it too, guess my brain auto-corrected the error or something.
For those that still don't get it, try this one:
if (inputHasErrors)
then { doNormalWork() }
else { showError("input has errors") }
It's actually a triple whammy:
1. the code shows errors when things are ok, and does work when things are not ok.
2. the code always thingks are ok even when they are not (and thus always shows an error)
3. it easy to understand how the coder got it wrong by mistake, it is easy to fix, but they are not allowed to fix it.
Admin
Doesn't Delphi have step-trace debugging for these?
Admin
Yes, the 'else' and 'then' are reversed. This would cause it to produce an error message if and only if it shouldn't. This is not the WTF.
Yes, the comparison will always be false. This would make the above bug irrelevant, because it can't even tell whether it should produce an error message or not. This is not the WTF either.
The real WTF here is that the code is obviously incorrect, and is producing false error messages every time it's being used, and it would take a matter of seconds to fix this, but the programmer was told not to fix it, because the users would think there was something wrong if they stopped getting false error messages all the time.
Admin
the first WTF: why he converts the DeliveryNumber to a string before checking it?
Admin
Given that the "lots of stuff processing the delivery" code has never been run, the chance of that code being correct is slim. Putting that code back into the system really might be more trouble than it is worth.
Admin
@Josh
The quotes look "funny" because they are the U+8220 character, rather than the standard quote character. Why? Maybe because of a copy and paste from Word or something.
Also, there is no encoding specified in the page so your browser has to guess the encoding. Your browser may be guessing wrong and displaying weird-ass characters.
Kent
Admin
"[...] because the users would think there was something wrong if they stopped getting false error messages all the time. "
More than likely, the users never read the message box before anyway, so not having the "confirmation" dialog box would alarm them. :/
<a href="http://blogs.msdn.com/oldnewthing/archive/2003/09/01/54734.aspx">The default answer to every dialog box is "Cancel"</a>
Admin
http://blogs.msdn.com/oldnewthing/archive/2003/09/01/54734.aspx
Admin
Man. I'm really going to have to stop reading the comments. I think the biggest WTF on this blog is the number of people that just don't get it.
Admin
I really don't get why you would convert an integer to a string to check its validity. What were they thinking ? We all make mistakes, but that is just stupid !
Admin
THe WTF here isn't really the code. As Guayo said, mistakes like this are easy to make when you're banging out code.
The real WTF is, how did this get into production? This is a WTHTH?, "Who TF Tested This", or alternatively WTFWTT (Why TF Wasn't This Tested?).
How did this even get past a unit test? Ahhhh... no unit tests I suppose....
Is this a vendor app? LOL!
Admin
I have to agree with Chris. The number of people who don't get this is quite funny. Even though the Ed has snipped parts of the code, it is still possible to pick the logic flaw by the comments provided. The other point is that, in my experience, it is a common occurance for the user to ignore an error message. Having said that, the developer responsible should have both index fingers removed with a blunt axe for not testing adequately.
Admin
@Jeremy: U+8220 is "CJK UNIFIED IDEOGRAPH-8220 (dao)", looking like that: ?; you mean U+201C (8220 in decimal), but that is "LEFT DOUBLE QUOTATION MARK", i.e. left quote, used on both ends of the quote, that is the problem here.
@GaryMc: You know, I suppose the person believed there is something like "empty integer", which would get converted to ''. I have seen some novice programmers with such belief. (Maybe SQL's NULL is the cause for the belief? I don't know.) He probably searched for some IntegerIsEmpty function, but found none, so he invented this. The rest is "only" a switched then/else... But, definitely, the code was obviously never tested.
Admin
(I knew the character won't display :-), but why, just a simple 舠 ...)
Admin
Is IntToStr a Delphi function? It could be a very messy custom function that validates the delivery number while converting it to a string, and returns an empty string if not valid.
I know, I did stuff like that before I Knew.
Admin
@proffK
so the WTF would by: why is this function called IntToStr when it doesn't convert an integer value but the order-number.
anyway: the order number is declared as integer. so it doesn't make sense to convert it to a string at all.
and yes: IntToStr is a delphi function.
Admin
Could someone explain this WTF in layman's terms? I don't know Delphi...
Admin
Delphi (or rather Object Pascal) is fairly easy to read.
Conversion to C#-ish code alogorithm:
- Convert begin..end pairs to {..}.
- var is simply a variable declaration (local in this case).
- '=' is the comparison operator, not assignment (that's ':=').
- ' is a string delimiter, change to ".
Admin
Uggh.
I'd hate to find out what their software development cycle is like.. Actually, I think I know:
* Bang out code
* Push to prouction
* Cross Fingers
* ???
* Profit
:^}
Admin
Punish the developer for not testing? What if the developer was forbidden to spend time testing? Sounds like a good way to crush someone's soul.
Admin
Here's the WTF for all you people who can't read the commented sections of:
IntToStr(DeliverNumber) WILL NEVER RETURN A BLANK STRING! Therefore the green "snip" section of the code after the if statement WILL NEVER RUN. That's why the comments say "that will of course never run."
The functionality for processing deliveries had been there the whole time, but never would execute because of the dilapidated if statement.
Admin
Funny that this WTF came up at the exact same time some people came to me asking for a way to find blank values in an integer field in SQL server tables. I couldn't get it through to them that if it's an integer field, it will NOT be blank. The crappy software they use that accesses the SQL tables converts NULL (as well as a few other random values like -9 and -32768) to blank values in the display. So naturally, they think the value is blank in the database.
And seriously people, if you think you know enough about programming languages to attempt to come to this site and get the humor, you should be able to pick up the basics of whatever language is posted.
Admin
Manni: Some of the WTFs that are posted are easy to understand. But this Delphi one was way over my head. (I'm still scratching my head.) I wouldn't assume that just because YOU get it, others do too.
Admin
Mike: I'd really like you to get this one, so I'll try breaking it down.
Line 1: He's declaring DeliveryNumber as an integer. From the programming languages I've encountered, an integer will either be some uninitialized value that you have to test for, or it must be a number.
Line 5: His "If" statement. He's got a function called IntToStr, which should take an integer (DeliveryNumber, in this case) and return the textual representation. Languages like Visual Basic will allow you to use a number as a string, but other languages will force you to convert it before you evaluate.
This is where the WTF comes into play. The code that was clipped out below it and is now represented in green will NEVER get called. The error message listed below that will ALWAYS be called. Remember what I said earlier about integers? Most likely Delphi sets integer variables to 0 (zero) when they are declared, so even if the program never modifies the value, it will still have its starting value of 0 (zero).
When it is converted to text, it will be at least a one-character string: '0'. The "If" statement is checking to see if the value returned from IntToStr is a blank string. Therefore, this "If" statement will ALWAYS produce the error message and NEVER execute the code it's supposed to.
I don't mean to sound condescending, but that's how I come across. For example, the link in phrax's post earlier is to a PHP WTF site. I checked it out, and I don't know nearly enough PHP to get the WTF. Therefore, I left. I just thought the programming concepts were fairly basic in this WTF.
Admin
1st WTF: In Delphi, an integer is initialized to 0 when it is declared. You get that for free. Therefore the conversion to a string will NEVER return an empty string. It will always return the string representation of some number.
2nd WTF: Even if the if statement was able to detect a bad order number, the code that would be executed in the event that a cad order number was detected, is the code which would process the order. This is wrong. The first "then" block should contain the error message. This is all irrelvant anyway, since the if statement will never detect a bad order number.
3rd WTF: The error is ALWAYS thrown. regardless of the order number. The order is NEVER processed.
This whole procedure could be replaced with
<pre>
begin
ShowMessage('I feel like throwing an error now!');
end;
</pre>
Admin
Delphi doesn't initialize local integer variables (those on the stack). Not that it matters anyway because DeliveryNumber is being initialized in the first portion of the code that was cut out ("//[Snip - getting the DeliveryNumber]").
Admin
For all you non-delphi profficient people I will make it simple for you:
IntToStr() is a library function that converts and integer into a string - ok fairly simply.
IntToStr() will never return '' because obviously there isnt a number '' there is 0 but that would be '0'.
And string quotes in delphi are single quote '.
Like some1 said earlier - the biggest wtf here is people not getting it.
Admin
Guys, I am really into Delphi. Maybe my brain is sleeping now but I think this IntToStr function does not return an empty string. I can’t remember Delphi 1, but I think here it is something fishy. WTF?