- 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
Correct me if I'm wrong, but if you take away all of the containsKey and !=null checks, the pseudo-code is basically this:
It's possible they may have started with something like this and as they ran into NullPointerExceptions or missing keys (probably in production), they added the rest of the code, leading to the monstrosity we see today. It's what some coders like to call "iterative development".
Still, I'll be sure to keep a copy of today's code around for the next time a developer brags to me about their code being "dense".
Admin
Although I'm glad they used equalsIgnoreCase there. You never know which case of "*" they might use.
Admin
Admin
One thing left to say:
Sir, You're an idiot!
Admin
TRWTF is using 'text-align: justify' with a monospace font.
Admin
Cast to string?
Admin
Maybe it's a really long way of writing (!str.isEmpty())?
Admin
Admin
I think that tests whether the string passed as the argument to .equals() is empty or not. It's much more intuitive to write it as stringToTest.equals(""), or even better stringToTest.length > 0, but that's a pretty pointless suggestion given the level of WTF already present. That'd be like chiding a pilot for having a crease in his uniform during a freefall.
Admin
You're probably not going to see this.. but..
how do you figure that?
Admin
The better question would be does any of this do anything useful...
Admin
Congratulations, sir! I admire your bravery in facing potential NPEs!
Captcha: dolor (sit amet)
Admin
Admin
The asshole who wrote this needs to learn what a local variable does.
Admin
Unless i'm mistaken, i think it validates it's not blank --- that's not to say that it's a really weird way of doing so
Admin
Yes, it pretty much sums it all up. To zero.
Admin
The asshole who wrote this needs to learn an awful lot of things.
Admin
The asshole who wrote this does exactly what assholes are meant to do: he produces shit.
Admin
wipes tear of laughter from eye
It's funny because it's so true!!!!!
Admin
FTFY.
Admin
yeah it is checking if ther parameter returned in the () is not equal to an empty string. it's actually doing it correctly to avoid a NPE if the parameter returned is a null gotta lover the .toLowerCase().equalsIgnoreCase(...)
Admin
Nah. It should just be "equals", but should take a comparison function as a parameter.
I'll get my coat...
Admin
!"".equals(OtherString)
In other words, checking for "" != OtherString
Admin
P.S. You must have worked with Windows 2.x.
Admin
The !"".equals is an empty string check.
Admin
http://en.wikipedia.org/wiki/SIGINT_(POSIX)
Admin
Now this is a TDWTF. For me, the part that really did it is this:
Is the author unaware of the "equals" method? Is the author too lazy to leave out "IgnoreCase"? Or maybe the author just plain doesn't get "case"?
Any way I look at it, it leads to another laugh.
Admin
!string.IsNullOrWhiteSpace((...))
Admin
Admin
Apparently the coder(s) have never heard of org.apache.commons.lang.StringUtils.isBlank
Admin
I think you're reading a bit too much into things if you believe I was actually asserting that this article's alignment is a worse offense than the article's content.
Also, it's not really superfluous. Before I realized how the alignment was set, I thought the main focus of this WTF was how the code was spaced.
Admin
!"".equals(val)
is the same as
val != ""
Admin
Admin
Not exactly. == compares reference, .equals() compares contents.
a == b is only true if and b point the same location in memory, a.equals(b) is true if the contents of a and b do not differ. Now due to the way Java handles Strings, you will generally get the results you want from that, but you're asking for a different thing.
Admin
Fucks me up something proper if I hit it on my way to Ctrl+V, though...
Admin
"".equals checks to see if the other string is not null and has a length of 0. By negating this logic, it accept a string that is either null or has a length greater that 0 (strings can't have negative length). A much more elegant solution would make use of the length() method in the String class.
Admin
Yes, it does I think. It checks whether the expression inside the .equals() evaluates to an empty string.
Admin
"" would be an empty string (String.Empty).
.equals does a string comparison test.
Therefore !"".equals() tests if the string passed in is empty.
Admin
There are better ways to do it, but basically !"".equals(otherString) means that the other string is not empty (or not null, but in the above case it can not be null)
Admin
I see the SPAM detector has been switched on again.....
Admin
!"".equals(blah) is same as blah != ""
Admin
Sure. It tests to see that the field (after blanks have been trimmed) is not empty. I'm not sure why we had to convert it to lower case first...
Admin
"Not empty"?
Admin
Haven't any of you jerks heard of Conjuctive Normal Form? Sheesh...
Admin
Admin
Admin
would be 'and not an empty string equals the param value trimmed' or in english 'and the param value trimmed doesn't equal an empty string'
Admin
"Spell checkers make you week."
Admin
!"".equals(var) is the same as (var != ""), just a really, really strange way of making the comparison.
Admin
You don't do much Java, do you?