- 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
Wait..."0" means "true"? I think that may be TRWTF.
Admin
Whoooosh..
The sound of that WTF going over my head..
Admin
Never heard of "negative true logic?"...actually quite common in many hardware disciplines.
Admin
Besides the obvious bad practice of naming defined functions after people, rather than after what they do; Jan, Piet and Diederick are all identical.
Admin
Eighth. And I don't buy it. Too funny to be true.
Admin
Admin
Surely Legion would have been better than Hans?
Admin
Hans niet goedkeuren van deze stomme code!
Captcha: gravis (useless old sound card)
Admin
This is clearly better than my practice of naming all inline functions "Alex", "Jake" and "Mark"...
Admin
what the...
WHY are three of them exactly the same? This code is just plain twisted no matter how I look at it; at least they had the decency to surround the macros with parentheses to avoid unexpected side effects.
... it's the four dutchmen of the codepocalypse
Admin
Three out of four inputs return the same output. This may be true today, but perhaps the coder foresaw a need for that to change in the future.
Admin
No, one would need three Dutchmen to screw in a lightbulb (better be a large lightbulb... ;-), that's why the Hans solution will probably not work... Oh wait everyone's switching to LEDs these days...
Admin
You're complaining about functionality being duplicated?! That's hardly a WTF...
I am trying to remember if I ever thought it was smart to make my code 'tidy' using macros like that as disguised functions, when I first learned about the preprocessor...
Admin
Most of the times, you wonder how on earth something like this slips into the code. My guess: Poor programmer don't know what kind of errors there are and what to do with it and ask 4 people: Kees, Jan, Piet and Diederick. All came with a different solution. So, pragmatic as the programmer is, he implements all solutions but does make sure the 4 nitwits who advices him, do get blame forever in this code..
Admin
So what? The names are stupid, and two macros (or functions) would suffice, but is it WTF-grade code? It looks like it is even working!
Admin
I would guess that if the state is unknown or if there was some error it is safer to assume the needle is inserted than that it is retracted.
Admin
Many Hans make light work!
Sorry, couldn't resist, it has been a slow day.
Admin
What crappy translator did you use?
But what bothers me most is that I can't come up with a famous Dutch song or book or movie that has four characters named Jan, Kees, Piet and Diederick.... Jan and Piet share a song with Joris and Corneel, but these other guys are nowhere to be found in this WTF....
Admin
Admin
They went a step farther than one of my coworkers. He used to comment parts of his code like this:
// ask david this->AllData2 = true;
Admin
Real WTF-code is always working in some fashion. It is the way it goes about its business that is the true source of WTF.
And yes, my name really is Hans... And I'm doing the work of four people... And still finding time to post here ;-)
Admin
When that is a WTF then strcmp() is a WTF, too...
Admin
Or, more likely, they used to be all different but now three are the same. If the programmer was smart enough to recognise it might change, he'd have been smart enough to do it a better way in the first place.
Admin
Looks to me that it's an attempt at a finite state machine. In that case the comments would refer to the current state and the functions would return the next state. I can't be bothered working out the states to see if I'm right.
Admin
Admin
Admin
I think the comparison being made is that strcmp returns 0 if they are equal.
Admin
Probably because Dutch labor laws make it quite difficult and expensive to fire somebody.
Admin
CoDepocalypse: When two co-dependent people finally break up, explosively.
Admin
Maybe when the code was first written, those functions were different in some way.
If it was easier to change the macro definition instead of combining them into one and changing all of the calls, then there's your reason for doing so.
Sometimes people do things because they deem one course of action "less risky" than others, and even though it may be wtf'ish, it's not a true wtf when that happens.
Admin
It makes sense if you realize strcmp answers "What is the difference between the strings?"; not "Are the strings equal?".
if (!GetDifferenceBetween(s1, s2)) ...
Admin
strcmp() doesn't return a boolean...
Admin
And I thought I was bad for liberally using "steve" as a name for debug variables and functions...
Admin
The real WTF is using - rather than ~ for negation. Let's have some fun by putting thenoriginal code on a one's-complement machine
Admin
And the next "Tales from Interview" article is born: You are walking along a mountain trail and come across a fork with four Dutchmen. You don't know where to head and you know only one of them talks a truth. What do you do?
Admin
Admin
Admin
I know. C's "booleans" aren't really booleans. But nevertheless, strcmp() returns an integer type result, not a boolean type result (even though there IS no "boolean" per se). Since it has three possible results, it cannot possibly be considered a boolean.
And nor should it--strcmp() isn't "asking a question", so to speak. Does it make sense to say "Compare these two things. Yes or no?"? No, it doesn't. That's essentially what strcmp() is doing.
Admin
Oh! I know these guys, they were the crew of the "Left Shifting Duchman". Har har.
Admin
Many moons ago, I got the opportunity to rewrite a VB app where all the variables were either single characters or the names of the original author's friends and pets. If w = Bob Then ...
Admin
I'm guessing this is a Government System?: http://en.wikipedia.org/wiki/Jan_Kees_de_Jager http://en.wikipedia.org/wiki/Piet_Hein_Donner http://en.wikipedia.org/wiki/Jan_Peter_Balkenende Piety we can't find Diedrick, though, maybe he retired already....
Admin
what strcmp returns is not defined that clearly. It only guarantees to return 0 if strings are the same, <0 if the first is lexically first, and >0 if the last is lexically first.
Some(many/most/all) implementations may return s1-s2, but there is no guarantee of this. Point is, what the OP is saying is that strcmp returns 0 if two strings match - this is a little counter-intuitive. A function called 'copmpare' appears to return 'false' if two things match. Granted, there is (good?) reason for it, but nonetheless the point is well made.
Admin
Even wikipedia has an article on it.... http://en.wikipedia.org/wiki/Strcmp
Admin
I'm pretty sure I've seen at least one C library where strcmp was implemented as returning the int (s1[idx_first_difference] - s2[idx_first_difference]), treating the characters as unsigned. This definitely returned a lot more than 3 results.
That having been said, I've seen dozens of people other than me who've used its results as a boolean.
Note that the primary justification I've seen for the Unix truth values (where 0 is true and everything else is false) is that there are generally a lot more ways things can go wrong than there are that they can go right.
Note that I am a Perl programmer, at least partially because I believe everything should be a boolean, in addition to any other properties it may have.
Admin
Well, first, the example appears to be C or C++ and it seems most of us have been talking C, so I don't know why you're looking at PHP. Second, none of the URLs you provided indicate that it isn't the difference - they just leave it up to the implementer whether it is the difference, the numbers -1, 0, or 1, or something else. Note that it is easier to just use the results of subtraction, if it's not zero, rather than testing that in both directions to determine if it should be -1 or 1.
That having been said, depending upon it actually being the difference would be a major WTF, because I'm pretty sure I've also seen at least one implementation which did return -1, 0, or 1. I think I've also seen an implementation which returned the difference of four bytes at a time, apparently with some code to sign-correct if it was a difference between the first two characters in that quartet.
Admin
The year: 1961 We were building a large system for a new Air Force contract. Being short-handed, we subbed a test analysis tool to another division of our company, which needed work.
When it arrived, we glanced at the code. Like the Dutchmen, the programmer had made all the procedures names - Eric, Charley, Darlene, Shirley, ... But she went one step further. The arrays (all global, of course) were named Gin, Whiskey, Vodka, Rum, ....
Dan Covill San Diego
Admin
Sounds like it was for a government agency, where it takes four near retirement age people to do the job of one normal person.
Admin
Sometimes when I'm in the mood I name my variables after my ex-girlfriends. Haven't run out yet.
Admin
Ever had a function that returns Zero when it succeeded? int Main() for example?
Admin
Huh, they're not even appropriate dutchmen, they should have been Edsger, Guido, Henk, and Wietse.