- 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
I agree that "first" posters should be banned, preferably for life.
However, I also think that people who don't get punctuation, or are not able to spell "forum" or "daily", should also be banned. If I want to read crap like that, I can go to Myspace.
Admin
LAST!!!!
Admin
Damn that Schrodinger guy - and his cat too!
Admin
When I return a value of some type I don't pay much attention to, being a very careful programmer that doesn't want to be lazy with someone's outsurced code, I validate the result even if it might be unnecessary.
Converting the result to a string and comparing it with the known possible values is an easy and universal way to validate data; the precise exception handling completes the validation.
Of course this is wasted effort and it might have internationalization bugs, but all it takes to take this route is failure to recognize the easy case.
It is merely a scaled up version of
Admin
Just thought I'd offer a somewhat plausible theory as to how this code came to be.
When are you most tempted to use cheap outsourcing?
For a time consuming, but well defined project, of course.
One typical example of this would be to port an existing application to a new environment (i.e .NET)
Perhaps this c# property is copied from some language which does not have proper booleans?
Perhaps the original implementation used literal "true" and "false" for boolean values?
In that case the original code surely must have checked for other values for the "boolean" values.
Translate this to c# by copy-pasteing and make a semi-automatic translation and you might end up with this code.
Then imagine that you are paid to write working code, not optimized code. Perhaps you won't even check the source code of your getter and setter. Just do some automated test:
Getting and setting true and false booleans? Works!
Setting a non-boolean value? Generates exception.
OK, whats next?
Admin
So where do you think it's getting the value from, if not from a static version of the string? Is it plucking it out of thin air, maybe? Or perhaps the .NET runtime includes some cunning algorithm to generate the strings "True" and "False"?
They're fucking constants. That means they're stored statically in the runtime somewhere. And they're immutable strings. That means there's no reason to make a physical copy of them each time you assign them to a new variable. Ergo, Boolean.ToString() has no reason whatsoever ever to create a new object, QED.
Admin
The .net runtime sourcecode is meant to be protected by a NDA, but it's time to expose a little secret...
Admin
are you sure you didn't made this up?
just to start a discussion you know
about the life universe etc.
Admin
When John won the USPGA in 1991, that was indeed a WTF?!?!?
(Terrible pun, and I haven't read all replies yet... Shame on me!)
Admin
Hm, interesting new verb, what would it mean?
Admin
So, if I understand everyone, to summarize: there is a new Boolean type: BooleanFloat, implemented as a float, as follows:
Range of allowed values: 0.0 <= x <= 1.0
Initial defined values:
0.0 = false
1.0 = true
Expansion values:
0.2 = probably not
0.5 = maybe
0.8 = most likely
etc.
Future Expansion:
-1.0 = File Not Found
1.2 = NaB ([N]ot [A] [B]oolean)
And for WTF coders:
0.001 = "False"
0.002 = "FALSE";
0.999 = "True"
0.998 = "TRUE";
Leading to such code as (using "~=" to mean approximately equals):
if (newAndImprovedFloatBoolean ~= 1.0) {
// true
} else if (newAndImprovedFloatBoolean ~= 0.0) {
// false
} else if (newAndImprovedFloatBoolean == BooleanFloat.NaB) {
// it's not a boolean at all
} else ...
Admin
Damn emoticons ...
Make that: [ N ]ot [ A ] [ B ]oolean
Admin
>The Daily WTF zings Slashdot; Slashdot takes a shot at Digg. What's next? Digg attacks Fark?
And the BileBlog refers to the dailyWTF, I guess Hani should start providing us with TomCat WTF's.
T.
Admin
I think this is a pretty good WTF, notwithstanding all the other comments to the contrary. Let's see just how many WTFs there actually are here, just for the practice:
- Member variable not contained within the class (is it actually global? This may be a C# thing, but it looks odd to a C++ guy like me)
- Conversion of booleans to strings for comparison
- get method performs various sanity checks, but returns the underlying value in the end no matter what (i.e. sanity checks are totally redundant)
- set method fails to trust its strongly typed input
- get method fails to trust redundant safety check in corresponding set method
- Redundant variable creation and assignment in set method
- Gratuitous argument exception thrown for strongly typed method
- Multiple return paths (really only a style preference)
- Sanity checks ignore limited range of input data (this may not be accurate if C# allows "null" for a bool)
OK, so with a little bit of imagination, there are approximately 9 WTFs in 15 lines of code. This is getting pretty close to the magic 1:1 ratio!Admin
Great example for showing why we all need to move towards Test Driven Development. If they had used TDD, they would have had 1/10th the code and no WTF.
Admin
Hanlon's razor does wisely advise us to assume stupidity before malice. But the ISO9001 name has me wondering if this monstrosity is due not to stupidity or malice, but due in some twisted way to something much worse... the delusion of using ISO9001 compliancy to make things better.
Admin
the really scary thing is that you are seeming to make sense .My friend, you should work in marketing. [6]
But in XP, note that 0/0 returns "the result of this function is undefined"
Admin
Booleans are so hard that C doesn't even have them in most compilers.
Admin
Best physics-themed typo bash EVER!
Admin
There is nothing wrong here. The author is validating the contents of a /string/ not a boolean, it's just returning a boolean. When the string is "", "0" or some other invalid value, this code will handle it... though I'm not sure why return m_ISO9001 is there vs throw new ArgumentException.
Admin
i think you meant to say "if a boolean isn't true or isn't not false, then we haven't got some bigger issues to address, yes?"
Admin
The getter is actually interesting when multithreading is involved ... :)
Admin
A better name for a float-boolean would be foolean.
Admin
I think we should create our own new notation for measuring the "WTF-ness" of code, kind of like "Big O" notation. We will call our notation "WTF", of course.
So, for example, based on your analysis, this code was written at approximately WTF(.5). As you mentioned, WTF(n) where n is anything close to (or even above!) 1 is truly an impressive accomplishment.
Admin
Dude ... I think you don't get it. Dude.
Admin
Admin
Obviously a generated reply.
Admin
Ironic, but unfortunately, not surprising.
One example I read was that if you manufactured life preservers filled with cement and your procedures were documented, you could still get ISO 9??? approval.
Sincerely,
Gene Wirchenko
Admin
That sounds like a wonderful idea.
Let's take a vote. Everyone in favor of this new system cast 0.1 vote, opposed cast 0.98 vote
Admin
Dude, When you type property as a boolean, the value of the "value" keyword inside the property is guaranteed by the compiler to be the same type as the property is typed. SO, when the user in this case says
public bool ISO9001
{
get ....
<FONT color=#000000>This means that everywhere inside the</FONT><FONT color=#000000> pproperty, value must be a boolean. and cannot be a string. If a user tried to type
</FONT><FONT face="Courier New" color=#ff0000>objectvariable.ISO9001 = "TRUE";</FONT>
The compiler would squawk
"<FONT color=#ff0000>That property is a boolean. You can't set it to a string!</FONT>"
That's why the author of this WTF had to write, in the setter..
bool v_ISO9001 = value;
//can only be true or false
if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
v_ISO9001.ToString().ToUpper() == "FALSE")
he had to type v_ISO9001 as boolean because value is a boolean. And he had to use ToString() on that because to compare it with the string "TRUE" he had to change the boolean to a string first, The whole thing is mind-bogglingly obtuse.
Admin
No way, these are FANTASTIC consultants! I mean, you never know when Microsoft, in their infinite wisdom, will determine that toString() of a boolean should return "rich" and "poop" instead of "true" and "false", or "britney" and "kevin", or "day" and "night". I mean, this is future-proofing to the EXTREME!
I for one salute our new boolean overlords.
Trying to be remotely serious for just a moment... I don't know much about C#, I didn't even know bool was an object type that you could call a method on, but OK, that seems cool. Could a developer subclass bool? If they could, then it kind of makes sense... what if the value passed in is a subclass of bool that doesn't return "true" or "false"? Assuming you could do all that, and I don't know if you can or not, it seems like the person making the call should be slapped, not so much the consultant being so anal as to check for it (sometimes anal is good... this doesn't strike me as one of those places, but then again, if this were code for a Mars probe, I'd expect this wouldn't be considered even remotely anal, right?)
Admin
The developer is probably some just-out-of school kid who has learned (primarily) to respect your superiors and not question what you are told. He was told that every subroutine he coded had to check validity of parameters. They didn't tell him how and he knew better than to ask (causes loss-of-face, possibly embarasses the big-boss who made up the silly rule). So you sit down and code it following the rules.
As this guy moves up the chain after being forced to write code like this we of the modern democracies can hope that he remembers that respect for 'betters' is a concept fraught with peril. Remember, in the last 200 years there has never been a war between two countries that both had the ability to vote the leaders out of office.
Admin
Is that really true?
Admin
0.1
Totally agree
Admin
3rd Cod War - UK vs Iceland 1975-6. According to http://www.britains-smallwars.com/RRGP/CodWar.htm, a few shots were fired, and there was some ramming.
Admin
To answer yr question about subclassing, - the answer is No, Bool is a value type, and in .Net, value types are intrinsically sealed. (They cannot be used as a base Type)
This is because value types, (unlike reference types), are stored on the stack, (in a method's stack frame), with only their internal state. They do not have an object header, like a reference type, on the heap, which is where a reference type stores the pointer to it's Type's data structure...
Admin
And is Argentina democratic? If so, then the Falklands conflict counts too...
Admin
It is now, but it wasn't then.
Admin
Indeed. Democratically elected politicians usually know better than to lead their countries into war. They bring interventionist forces to bear on an international police action. Much better!
Besides, I can't think of any countries where the public gets to decide when to throw a guy out of office. Occasionally, a time comes when we get to vote a guy in...
Admin
There was a recall election in California not so very long ago.
Admin
...except for this post.
TDD glorifies incompetence and should be destroyed wherever it is found.
Admin
I tried it in Mono and it works as expected, if you give an integer to this bool property, the compiler refuses to do its job, tha's why converting value to bool in the "set" is useless. The property is defined as giving back a bool (with "public bool ISO... {") but it also means that the value has to be a bool too.
Admin
Could you please explain the logic -- if any -- behind this declaration?
Admin
I'm amazed at the depth and breadth of knowledge (displayed here in the many comments) on the immensely complicated topic of truth in programming.
I doubt there is anything I could add that hasn't already been said. But for the benefit of any *novice* programmers who might find this all a bit perplexing, let me take this opportunity to recommend the excellent book "TRUE In A Nutshell". While the book has an obvious Unix focus, it addresses most of the issues pertinent to ANY application of TRUE.
Note: In light of ISO9001, this book may be in need of a revision.
Admin
Sure.
1. "Program testing can be used to show the presence of bugs, but never to show their absence." -- Dijkstra. You cannot rely on tests to tell you when a program is complete.
2. To see what can happen when a programmer hacks away at a program until it passes in-house tests, read this: http://courses.cs.vt.edu/~cs3604/lib/Therac_25/Therac_1.html (note that there are more pages)
3. Authors are promoting TDD like it's revolutionary idea that hasn't been appreciated before. Actually, it's the technique that new programmers use when they don't have a clue, and in the 1960s and 70s Dijkstra, Gries, and Mills all "appreciated" it for what their experience showed it to be: a horribly unreliable way to write software. They developed better techniques that are well-documented and that programmers ought to be using.
4. Despite this, writers on TDD like Robert Martin seek to brain-damage new programmers with the belief that the developments of the 60s and 70s are irrelevant and that TDD is the way to go, as in this exerpt from a student-"teacher" dialogue on Martin's web site.
Well Bob, they're teaching us to program, not to bang a rock on the keyboard until the tests work. That's what I mean by "glorifying incompetence."
Admin
Reading your post, it nearly looks like unit tests are evil. But this is not true and I think it is not what you meant. I aggree that the acceptance of a program should not rely solely on automatic tests, but they are a great tool to find bugs a human tester might overlook(*), and they are usefull to check if changes have undesired side effects.
(*) A carefull tester with a very detailed testing script is not likely to overlook bugs, but the effort to write such a script is identical to writing the unit test, and the computer's work is cheaper than the tester's.
Admin
This must be quantum physics!
Admin
No, it isn't. The superposition in quantum physics delivers more predictable results.
Admin
It's not what I meant. Unit tests are important to verify, after you have written code, that your reasoning and your typing are correct. But passing unit tests should never be the driving goal of development in a professional setting, as Martin would have it. The goal should be reliable solution. And the place to educate yourself to the point where you can program well enough to do that is the home or classroom, not the office.
Admin
Wow, and only 3 seperate exit points in the get property? Talk about unstructured code, sheesh. I love seeing 1960's style code in an object oriented language....