Comment On The Four Dutchmen

"It's some nice code," smiled the software architect at Petr Valasek's company, "it needed refactoring before it was ever written. But the good news is, you get to refactor it now." [expand full text]
« PrevPage 1 | Page 2Next »

Re: The Four Dutchmen

2009-07-06 09:06 • by toth
Wait..."0" means "true"? I think that may be TRWTF.

Re: The Four Dutchmen

2009-07-06 09:07 • by Quango
Whoooosh..

The sound of that WTF going over my head..

Re: The Four Dutchmen

2009-07-06 09:20 • by A-Nona-Mouse (unregistered)
273155 in reply to 273150
Never heard of "negative true logic?"...actually quite common in many hardware disciplines.

Re: The Four Dutchmen

2009-07-06 09:25 • by Drew (unregistered)
273156 in reply to 273151
Quango:
Whoooosh..

The sound of that WTF going over my head..


/*case GIS_NEEDLE_STATE_RETRACTED:*/
#define Kees (m_nlGISRetracted &= ~(1 << nIndex))

/*case GIS_NEEDLE_STATE_UNKNOWN: */
#define Jan (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_INSERTED: */
#define Piet (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_ERROR: */
#define Diederick (m_nlGISRetracted |= 1 << nIndex)


Besides the obvious bad practice of naming defined functions after people, rather than after what they do; Jan, Piet and Diederick are all identical.

Re: The Four Dutchmen

2009-07-06 09:29 • by tetsu (unregistered)
Eighth.
And I don't buy it. Too funny to be true.

Re: The Four Dutchmen

2009-07-06 09:34 • by Not THAT Alex (unregistered)
273158 in reply to 273150
toth:
Wait..."0" means "true"? I think that may be TRWTF.

That's because it's using file-not-foundian logic.

Re: The Four Dutchmen

2009-07-06 09:35 • by Stephen Melrose
Surely Legion would have been better than Hans?

Re: The Four Dutchmen

2009-07-06 09:36 • by deekay (unregistered)
Hans niet goedkeuren van deze stomme code!

Captcha: gravis (useless old sound card)

Re: The Four Dutchmen

2009-07-06 09:39 • by GalacticCowboy
This is clearly better than my practice of naming all inline functions "Alex", "Jake" and "Mark"...

Re: The Four Dutchmen

2009-07-06 09:40 • by kastein
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

Re: The Four Dutchmen

2009-07-06 09:48 • by umpaloompa (unregistered)
273163 in reply to 273156
Drew:
Quango:
Whoooosh..

The sound of that WTF going over my head..


/*case GIS_NEEDLE_STATE_RETRACTED:*/
#define Kees (m_nlGISRetracted &= ~(1 << nIndex))

/*case GIS_NEEDLE_STATE_UNKNOWN: */
#define Jan (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_INSERTED: */
#define Piet (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_ERROR: */
#define Diederick (m_nlGISRetracted |= 1 << nIndex)


Besides the obvious bad practice of naming defined functions after people, rather than after what they do; Jan, Piet and Diederick are all identical.


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.

Re: The Four Dutchmen

2009-07-06 09:49 • by J., another Dutchman (really!) (unregistered)
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...

Re: The Four Dutchmen

2009-07-06 09:49 • by Booboo (unregistered)
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...

Re: The Four Dutchmen

2009-07-06 09:55 • by Merty (unregistered)
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..

Re: The Four Dutchmen

2009-07-06 09:58 • by D (unregistered)
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!

Re: The Four Dutchmen

2009-07-06 10:02 • by D (unregistered)
273168 in reply to 273162
kastein:

WHY are three of them exactly the same?


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.

Re: The Four Dutchmen

2009-07-06 10:13 • by Stoker (unregistered)
273170 in reply to 273164
J., another Dutchman (really!):
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...


Many Hans make light work!

Sorry, couldn't resist, it has been a slow day.

Re: The Four Dutchmen

2009-07-06 10:21 • by JavaJaap
273171 in reply to 273160
deekay:
Hans niet goedkeuren van deze stomme code!


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....

Re: The Four Dutchmen

2009-07-06 10:21 • by Adriano
273172 in reply to 273163
umpaloompa:

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.

Because adding switch branches and defines as needed in the future is that much more obscure...

Re: The Four Dutchmen

2009-07-06 10:30 • by Kiss me I'm Polish
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;

Re: The Four Dutchmen

2009-07-06 10:49 • by Hans (unregistered)
273179 in reply to 273167
D:
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!


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 ;-)

Re: The Four Dutchmen

2009-07-06 11:18 • by Lupus.Umbrae (unregistered)
273182 in reply to 273150
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Re: The Four Dutchmen

2009-07-06 11:50 • by Kevin (unregistered)
273186 in reply to 273163
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.

Re: The Four Dutchmen

2009-07-06 11:51 • by Eh (unregistered)
273188 in reply to 273156
Drew:


/*case GIS_NEEDLE_STATE_RETRACTED:*/
#define Kees (m_nlGISRetracted &= ~(1 << nIndex))

/*case GIS_NEEDLE_STATE_UNKNOWN: */
#define Jan (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_INSERTED: */
#define Piet (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_ERROR: */
#define Diederick (m_nlGISRetracted |= 1 << nIndex)


Besides the obvious bad practice of naming defined functions after people, rather than after what they do; Jan, Piet and Diederick are all identical.


toth:
Wait..."0" means "true"? I think that may be TRWTF.


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.

Re: The Four Dutchmen

2009-07-06 12:07 • by Dylan (unregistered)
273189 in reply to 273182
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Strcmp returns (string1 - string2); how is that related to a state var that uses 0 for yes?

Re: The Four Dutchmen

2009-07-06 12:10 • by Smash King
273190 in reply to 273162
kastein:
WHY are three of them exactly the same?
Because Jan, Diederick and Piet are clones. We just don't know if the original is one of them or someone else that was cut away from the project.

Re: The Four Dutchmen

2009-07-06 12:18 • by Jeremy (unregistered)
273191 in reply to 273189
Dylan:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Strcmp returns (string1 - string2); how is that related to a state var that uses 0 for yes?


I think the comparison being made is that strcmp returns 0 if they are equal.

Re: The Four Dutchmen

2009-07-06 12:23 • by Anon (unregistered)
273192 in reply to 273156
Drew:
Quango:
Whoooosh..

The sound of that WTF going over my head..


/*case GIS_NEEDLE_STATE_RETRACTED:*/
#define Kees (m_nlGISRetracted &= ~(1 << nIndex))

/*case GIS_NEEDLE_STATE_UNKNOWN: */
#define Jan (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_INSERTED: */
#define Piet (m_nlGISRetracted |= 1 << nIndex)

/*case GIS_NEEDLE_STATE_ERROR: */
#define Diederick (m_nlGISRetracted |= 1 << nIndex)


Besides the obvious bad practice of naming defined functions after people, rather than after what they do; Jan, Piet and Diederick are all identical.


Probably because Dutch labor laws make it quite difficult and expensive to fire somebody.

Re: The Four Dutchmen

2009-07-06 12:39 • by RobFreundlich
273195 in reply to 273162
kastein:
... it's the four dutchmen of the codepocalypse


CoDepocalypse: When two co-dependent people finally break up, explosively.

Re: The Four Dutchmen

2009-07-06 12:49 • by sadwings (unregistered)
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.

Re: The Four Dutchmen

2009-07-06 12:55 • by fourchan
273199 in reply to 273191
Jeremy:
Dylan:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Strcmp returns (string1 - string2); how is that related to a state var that uses 0 for yes?


I think the comparison being made is that strcmp returns 0 if they are equal.


It makes sense if you realize strcmp answers "What is the difference between the strings?"; not "Are the strings equal?".

if (!GetDifferenceBetween(s1, s2)) ...

Re: The Four Dutchmen

2009-07-06 12:59 • by toth
273200 in reply to 273182
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...


strcmp() doesn't return a boolean...

Re: The Four Dutchmen

2009-07-06 13:46 • by Michael S (unregistered)
And I thought I was bad for liberally using "steve" as a name for debug variables and functions...

Re: The Four Dutchmen

2009-07-06 13:49 • by Anonymous Coward (unregistered)
273202 in reply to 273166
The real WTF is using - rather than ~ for negation. Let's have some fun by putting thenoriginal code on a one's-complement machine

Re: The Four Dutchmen

2009-07-06 13:56 • by Synchronos (unregistered)
273203 in reply to 273166
Merty:
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.


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?

Re: The Four Dutchmen

2009-07-06 16:01 • by Code Dependent
273211 in reply to 273195
RobFreundlich:
kastein:
... it's the four dutchmen of the codepocalypse
CoDepocalypse: When two co-dependent people finally break up, explosively.
Hey!

Re: The Four Dutchmen

2009-07-06 16:17 • by Mike (unregistered)
273213 in reply to 273200
toth:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...


strcmp() doesn't return a boolean...

C doesn't have booleans. It uses ints where 0 is false and any value that isn't 0 is true. That means strcmp will return "false" when the strings are equal and "true" when they are not.

Re: The Four Dutchmen

2009-07-06 16:40 • by toth
273215 in reply to 273213
Mike:
toth:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...


strcmp() doesn't return a boolean...

C doesn't have booleans. It uses ints where 0 is false and any value that isn't 0 is true. That means strcmp will return "false" when the strings are equal and "true" when they are not.



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.

Re: The Four Dutchmen

2009-07-06 16:58 • by YonmaN (unregistered)
Oh! I know these guys, they were the crew of the "Left Shifting Duchman". Har har.

Re: The Four Dutchmen

2009-07-06 17:35 • by Steve (unregistered)
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 ...

Re: The Four Dutchmen

2009-07-06 17:53 • by $$$ (unregistered)
273221 in reply to 273171
JavaJaap:
deekay:
Hans niet goedkeuren van deze stomme code!


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....


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....

Re: The Four Dutchmen

2009-07-06 17:57 • by Really? (unregistered)
273223 in reply to 273189
Dylan:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Strcmp returns (string1 - string2); how is that related to a state var that uses 0 for yes?


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.

Re: The Four Dutchmen

2009-07-06 18:02 • by Really? (unregistered)
273225 in reply to 273199
fourchan:
Jeremy:
Dylan:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...

Strcmp returns (string1 - string2); how is that related to a state var that uses 0 for yes?


I think the comparison being made is that strcmp returns 0 if they are equal.


It makes sense if you realize strcmp answers "What is the difference between the strings?"; not "Are the strings equal?".

if (!GetDifferenceBetween(s1, s2)) ...

Not sure which language it returns the difference in...
Neither of the examples below (which I would assume are among the most common) claims to return the difference.
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
http://us2.php.net/manual/en/function.strcmp.php

Even wikipedia has an article on it....
http://en.wikipedia.org/wiki/Strcmp

Re: The Four Dutchmen

2009-07-06 18:04 • by tgape
273226 in reply to 273215
toth:
Mike:
toth:
Lupus.Umbrae:
toth:
Wait..."0" means "true"? I think that may be TRWTF.


When that is a WTF then strcmp() is a WTF, too...


strcmp() doesn't return a boolean...

C doesn't have booleans. It uses ints where 0 is false and any value that isn't 0 is true. That means strcmp will return "false" when the strings are equal and "true" when they are not.



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.


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.

Re: The Four Dutchmen

2009-07-06 18:21 • by tgape
273227 in reply to 273225
Really?:
Not sure which language it returns the difference in...
Neither of the examples below (which I would assume are among the most common) claims to return the difference.
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
http://us2.php.net/manual/en/function.strcmp.php

Even wikipedia has an article on it....
http://en.wikipedia.org/wiki/Strcmp


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.

Re: The Four Dutchmen

2009-07-06 18:36 • by Really? (unregistered)
273231 in reply to 273227
tgape:
Really?:
Not sure which language it returns the difference in...
Neither of the examples below (which I would assume are among the most common) claims to return the difference.
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
http://us2.php.net/manual/en/function.strcmp.php

Even wikipedia has an article on it....
http://en.wikipedia.org/wiki/Strcmp


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.

Sorry, no-one explicitly specified language (although the WTF itself was in C), so I thought I'd cover other bases....

Your second sentence is exactly my point. An implementation may return the difference, but we cannot assume this is the case. The result is not defined to be the difference, but rather to be negative if s1<s2, positive if s1>s2 and 0 if they are equal. So, my original point was that the result may be the difference, but does not have to be the difference.

Re: The Four Dutchmen

2009-07-06 19:41 • by Dan Covill (unregistered)
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

Re: The Four Dutchmen

2009-07-06 20:54 • by David F (unregistered)
Sounds like it was for a government agency, where it takes four near retirement age people to do the job of one normal person.

Re: The Four Dutchmen

2009-07-06 23:04 • by AndyCanfield
Sometimes when I'm in the mood I name my variables after my ex-girlfriends. Haven't run out yet.

Re: The Four Dutchmen

2009-07-07 03:13 • by Not always wrong (unregistered)
273301 in reply to 273150
toth:
Wait..."0" means "true"? I think that may be TRWTF.

There's only one way for a comparison to be true, but it can be false in many ways.

Ever had a function that returns Zero when it succeeded?
int Main() for example?
« PrevPage 1 | Page 2Next »

Add Comment