- 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'm guessing you changed the variable names because that would appear to always return false and ret isn't defined in the method. If ret is an instance variable... well, I don't even want to think about that.
Admin
I hope that "ret=true" really means "isnull=true", otherwise all that beatuiful short-circuit evaluation is for nothing...
Admin
The best part is that it'll always return false. :P
Admin
I sense the future will soon bring Issue #781335:
str.equals("_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null_null")
Admin
Of course the whole thing could be:
return (str == null) ||
(str.equals("__")) ||
(str.equals("__null")) ||
(str.equals("_null_")) ||
//Added for Issue #107724
(str.equals("_null_null")) ||
(str.equals("null__")) ||
(str.equals("null__null")) ||
//Added for Issue #126185
(str.equals("null_null_")) ||
(str.equals("null_null_null"));
And I hate all the extranneous parens. Why do poeple think that makes it more readable?
return (str == null
|| str.equals("__")
|| str.equals("__null")
|| str.equals("_null_")
|| str.equals("_null_null") //Added for Issue #107724
|| str.equals("null__")
|| str.equals("null__null")
|| str.equals("null_null_") //Added for Issue #126185
|| str.equals("null_null_null"));
is much better IMO. Or even better, create this during class loading:
Set nullStrings = new HashSet();
nullStrings.add("__");
nullStrings.add("__null");
nullStrings.add("_null_");
nullStrings.add("_null_null"); //Added for Issue #107724
nullStrings.add("null__");
nullStrings.add("null__null");
nullStrings.add("null_null_"); //Added for Issue #126185
nullStrings.add("null_null_null");
Then the method becomes:
return str == null || nullStrings.contains(str);
Admin
In terms of the actual WTF here, it's hard to say whether this is the result of bad code in the application or a third party tool. I've had to do stuff like this to deal with both. So this looks like a work around to a WTF to me, not the WTF itself.
Admin
I'm not entirely sure that I should read this blog. I have nasty flashbacks to the system my cousin and I helped to maintain (and untangle); a bookkeeping program written in Pascal and which had about 4000 global variables and not one single local variable.
That was fun. Not.
Admin
Is anyone else surprise that there are at least <FONT color=#008200>#126185</FONT> issues reported so far?
Admin
<FONT face="Courier New"><sarcasm></FONT>
<FONT face=Arial>What about the value of NULL or _NULL or the infamous _NULL_NULL? I think the code is buggy and needs to take those risks into consideration.</FONT>
<FONT face="Courier New"></sarcasm></FONT>
Admin
Someone's data is in need of a good cleaning!
Admin
And how did you come to that conclusion?
Admin
I agree.
I think the submitter of this code should tell us a little about the project and why something like this is necessary.
Admin
It does. Ugh, I *really* need to get better at proofing the "anonymizing" a bet better ... thanks for pointing it out.
Admin
I agree as well.
It looks like the author is trying to handle what the system "thinks" is null in a nice way...this system seems to have multiple ways of setting variables to 'null'.
Admin
How about trying to compile the snippet after you modify it?
Admin
Hey Alex, it would be a good idea to keep the original post, with mistakes crossed out and new lines added. It is not funny when you see people are talking about ret=true and you can't find it in the post.
Admin
Hey at least it's commented!
Admin
Maybe a regular expression that would match the word "null" with any number of leading, trailing or in-between underscores would be nicer... oh, wait! This wouldn't match "__". Darn it!
Admin
Sweet sassy molassy. If I saw this in production code in my office, I think I'd quit immediately and maybe even set fire to the building on the way out.
Interestingly, an empty string will return false. Not sure if that's an oversight or an f'ed up twist on the rule.
Admin
<font size="1">Evidently, "null" is not null.
Makes sense.
</font>
Admin
I've had to write code similar to this. A third party (stock market data provider) started sending us strings containing the word "null" instead of just empty strings. Without telling us first.
Admin
<font size="1">
(((why worry about ((operator precedence?))))</font>
Admin
Without knowing the context in which this function was used I can't share your sentiments.
Admin
I agree with the people who say this is actually an attempt to clean up other wtf code.
The thing which interests me is that, among all the things they allow as a null string, an empty string is not one of them.
Given that it appears that bad code elsewhere in the system concatenates "null" strings and then other code that gets these concatenated null strings works better if the two concatenated strings are considered null, it follows that it is happy to accept a null string concatenated with an empty string is null ... so why not empty strings?
Indeed this looks like a bunch of extremely bad code written to avoid the apparently dire consequences of assuming empty strings are null. No doubt one can have fun with their system by entering the surname "__" or "_null".
Admin
WTF. Why not just use str.Find("null") and str.Find("__"). That would handle all of these stupid cases, including Issue #eventy-billion. That is, unless for some damn reason "null" is a valid string.
Admin
Any developer knows it should be
right? ;)
Admin
If this is Java (which I suspect from the return type of boolean rather than bool), then you can also do nullStrings.add(null) and nullStrings.contains(null) will return true.
I've often wondered about the following common paradigm:
boolean result = false;
if (blah || bleah || yadda || bubba) then result = true;
return result;
I keep thinking: why not return blah || bleah || yadda || bubba...
I suppose life could be worse...
return (blah || bleah || yadda || bubba) ? true : false
Admin
I don't normally defend WTF posts, but I have to agree with some of the others posting so far. On more than one occaision, I've had to write one-time tools like this to either fix a user mistake where thousands of database records were changed, or to fix third party software errors where another tool freaked out and changed data. Then again...
Hardcoding each of the potential possible values for null is just retarded. As soon as someone comes across "_null__" or "__null_null" or some other bizarre combination of "null" and underscores, the tool will have to be recompiled. Use regular expressions for god's sake!!!
Admin
Why would anyone want to use null_null_null though?
Admin
http://www.google.tt/search?q=null_null_null&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official
Admin
The real WTF is what kind of a mega-super-moronic system *created* those various assignments that must all be treated as null strings?
I mean... "<FONT color=#848284>null__null</FONT><FONT color=#000000>" as the *value* of a string to mean that the string is null?</FONT>
What the FFFFFFFFFFFFFF?
Whatever happened to ""?
Admin
True, str.equals("blah") || str.equals("blah") really makes me scratch my head trying to figure out the operator precendence. You'd think it would evaluate to the result of the first method call or'd with the result of the second method call. But you never know, it could also evaluate to the result of the first method call or'd with the result of the second method call or even the result of the first method call or'd with the result of the second method call. It's really hard to say.
Now (str.equals("blah")) || (str.equals("blah")) will definitely evaluate to the result of the first method call or'd with the result of the second method call.
Totally.
Admin
Gawd... I think I know where __null and null__ and all other variants comes from.
It looks like a string is used to hold values for several fields at once, like a comma-separated line, except using __ as the delimiter, or like a bitmask.
So if the semantics of the strings is
lastname__firstname__zipcode
you could have
papadimoulis__alex__12345
but if Alex was a naughty boy he may have left out his last name or zip code or what have you and different versions of the interface may have assigned "" or "null" to represent null fields, thus giving rise to
__alex__
__alex
__12345
etc.
I hope I'm wrong.
Admin
This would explain why no test for "" or "null" since the input would always have the underscores added before the test.
Admin
Reloacate to Cleveland! +o( Now there is a WTF!
Sorry, I lived in the "mid-west" once before. I aint going back!
I'll stay in the Rockies.
Admin
LMAO! - [:D]
Admin
Depends on the function. I use the paradigm to avoid multiple exit points. Instead of returning from some location within the if () {} else {} statement, I set the return value and have only one point where the functino returns. If it's a simple boolean return, or something directly computed, that's a different story. It's a matter of knowing when to use the paradigm and knowing when not to use it.
Admin
About the job position, if my code was posted on your site, does that count as a refecence ? ;-)
Admin
In addition to rocking (you've heard the song, right?), we are officially #1*.
<FONT size=1>* poorest city in the US</FONT>
Admin
"" != null in Java.
Admin
Correction to my post: the separator is _ not __. The occurrence of __ signifies that all 3 possible values in the string are blank.
If this is right (which it probably is, sadly) this design is pretty moronic.
There are, however, possible explanations. Say the app is tracking tasks, each of which returns some string (which may be null). You could store each task's result in some session variable, and when your user is done write it to your db as a single string separated by _. This makes it extensible: if you add another task, you don't have to add a field to your db. If each task's result uniquely identifies the task, this schema allows you to data-mine your db for questions like "how many users did task X right before task Y and didn't return null for either task"; "how many users stopped the whole process immediately after task X"; etc. You could store one record per task for each user but that would mean a lot more rows in your db and make said data mining possibly harder.
Admin
Agreeing with everyone elses comments about this guy, it's not that function, but the rest of the code that would seem to be the WTF. Of course, that's also what Alex said in his post about not even wanting to see the rest of it.
But on a side note, I do enjoy this one:
I'd have to argue that all people have experience in their own line of work... :P
Admin
This can be useful under certain circumstances to avoid C4800 compiler warning.
Your choice:
return (blah || bleah || yadda || bubba ) ? true : false
return (blah || bleah || yadda || bubba) != 0;
Admin
Consider recent graduates looking for jobs. I was trying to dissaude those (unfortunate) folks ;-).
Admin
I don't find the single exit point to make anything clearer. It makes the code path merge back on itself artifically (making the code more complex) instead of a clean branch. It keeps the compiler from ensuring that all the code paths actually return something meaningful. I like to be able to follow the code and easily see what it returns. I don't like to have to walk through a bunch of extra code to see whether the returnValue variable is changed later on in the method.
Admin
Arguably the best symphony in the country and a fantastic antique car museum, though
Admin
I'd say it's a WTF on both ends. You'd think the developer would maybe, just maybe try to either determine the cause of the various forms of strings-containing-nulls that come or at least try to do some sort of simple data cleansing so he/she doesn't have to add a new conditional every time a new issue comes in.
Admin
Storing delimited strings in database fields makes baby Jesus cry.
Admin
Why doesn't it surprise me that Oracle is in the result set?
Admin
Baby Jesus deserves it. Sometimes that's actually a good way to do things.