- 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
No. He wants to ensure that googleId either has a value, or it contains null. If it has a value that the language he's using understands as "equivalent to null" (apparently for PHP there are several of these, for javascript it would be "undefined") he wants it to be explcitily set to null. That is, if googleId looks like a null, ensure that it's actually a null, by setting it. Otherwise, he wants it to keep its value.
Not difficult, and possibly necessary, depending on the application. The use of the ternary is moderately annoying, but legit. (My personal stylesheet says ?: is only used in string building, and not as a generic substitute for if/else, but this is idiosyncratic)
captcha - minim - ahctpac
Admin
Admin
Wow, you are like waaaaay waaaaaaaaaaaaaay too serious for this site... or are you covering for that big whooooosh that you missed?
Why don't you join in the thread about detecting really null? It actually has some seriousness to it...
Admin
Admin
Woah there, take a deep breath. If you don't find his comment amusing or have any constructive criticism, just move on. It's really quite easy.
Admin
Depending on where 'north-east Asian steppes' and 'Siberia' intersect.
I also like that after fiddling with the camel toes he then applies coding 'for mating'.
Admin
Bump, I was just going to write the same thing. I accidentally broke this for one of my classes the other day. Had I not caught it as part of TDD cycle, this would have been the hacky way to fix (when fixing the == operator wasn't immediately possible).
Admin
Admin
they even added a syntactic suger for that in php 5.3, so you can write:
googleId = googleId ?: null;
I guess that in 5.5 they should go one step further:
googleId =?: null;
Now seriously, TRWTF is that instead of finding the source of unknown/false/0/null/""/undefined/uninitialized/whatever bug, they mask it out by assigning null.
Admin
Admin
The googles... they do nothing!
captcha: nulla
Admin
Now that we've firmly established that the last WTF is not a WTF (although I personally find the comment of the submitter enfuriating to a WTF-degree, as it reminds me of the attitude shit-for-brains coworkers that "cleaned up" MY code had), can it please be labeled as such?
Admin
The penultimate WTF is not a real WTF, either, simply a predictable result of hungarian-type naming conventions, processed by a grade-school sense of humor.
Hungarian-type naming conventions, yes, are a RWTF.
Admin
Admin
More efficient? Not likely. Your version doesn't save much by way of instructions (like maybe two), so it would have to be executed a lot of times to make any difference in terms of efficiency.
More readable? Yes, but it still requires a comment, since the actual meaning of "googleId==null" is still obscure.
Admin
This looks to be a fine Expert System design. Logically, anything that matches IsEmpty fails to match IsNotEmpty. Further facts and rules follow based on the value.
Remember the classic PROLOG problem an odd length list is not an even length list. Assume zero length is even.
evenlen([]). evenlen([H|T]) :- oddlen(T). oddlen([H|T]) :- evenlen(T).
Admin
To those who ask how the camel gets involved: In German this could happen when you try to translate the term "column" (of a row/column grid). In German this word is "Spalte", which translates to cleavage or gap, but when used for a body part and in slang mode, comes out as camel toe. So my guess is that Russian works a bit similar to german here.
Admin
I was thinking it was a corruption of "camel case".
Admin
Admin
Admin
Just because code functions correctly doesn't fully exempt it from WTFery. You can easily dip into WTF territory based on style and comments. In the case, the code and its comment were still screwy enough to throw several people for a loop. That becomes even more of a problem because that line's one out of hundreds or thousands that someone else modifying the code must look at and understand.
Compare:
versus:
When you're doing something slightly kooky at first glance (like assigning null to a variable that's already null), it really helps to be explicit about why you're not insane.
Hell, I once did something similar (apparently assigning a value to a variable that already has that value) in code that only I would ever look at, and I still threw in three lines of comments just to be clear so I knew I wasn't suffering from some sort of dementia.
Admin
FTFY.
And I thought I was abusing properties when I made the getter read from a stream...
Admin
Oh wow, win. That was one of the best comments I've read in a while. Well played.
Admin
That is because it is not a bug, it is a feature. It is explicit at the language definition, and on the manual.
Also explicit are the hiden conversions to/from null that punish everybody that try to access a database from PHP. (Does anybody code on PHP and not access a database?) They are a feature too.
Admin
A couple more: building up expression trees or other similar objects.
E.g. "x * (2 + y)" could produce a tree where the root is a * operator, its left child is x, it's right child is a + operator, etc.
I've used this to great effect in the past.
Basically if you'd have functions called stuff like "make_add", "make_and", etc. or similar, I think it is likely to make perfect sense to overload.
Then of course there's overloading [] in container objects, which makes perfect sense.
Finally, string I/O in C++ also makes sense; that's abusing << and >> a bit, but I consider it legit. The alternatives aren't pretty.
My initial reaction was that the toString() one wasn't that much of a WTF either, but I don't do much Java programming and missed the infinite recursion in it.
Admin
It's only a problem when dealing with large values of null.
Admin
1.) Fix camel toe. 2.) ????? 3.) Profit!
Admin
Admin
E. Darwin, your point is well seen. I guess elaborating on kookyness is always a good idea.
Admin
Admin
public String TWDTFComment { set { comment.text = "frist"; } }
Admin
Admin
Admin
you really think that: if(googleId==null){ googleId=null; } is in any way better than the original code? It should be: if(typeof(googleId)=="undefined"){ googleId=null; } or at least: if(googleId==null && googleId!==null){ googleId=null; } or put a proper way of testing for undefined/false/0 in PHP/JS language, but the point is that the condition should clearly indicate the intent, which is precisely: change it to null if it is not null, but resembles null...
sorry for repeating, but TRWTF is they did not debug the source of these "unreal" null, and choose to overwrite it with real null.
Admin
The property WTF is STILL better than the one my (ex)coworker inflicted upon me. Nothing like a non-repeatable read to really make you doubt your sanity for a while!
bool _MyVar = false; public bool MyGodAwfulProperty { get { _MyVar = !_MyVar; return _MyVar; } set { _MyVar = value; } }
Admin
Because the unicycle was in the shop?
Admin
Admin
The Russian comments are funny engrish, but how do they qualify as a WTF? They are written by a non-native speaker, but are none-the-less comprehensible, which is more than I can say for a lot of comments I've read (and surely some that I've written).
Admin
Or possibly, spoke perfectly good English, but had something else on his mind while writing the comment... busy web surfing while waiting for code to compile :)
Admin
Don't forget to check for tri-states...
HideCenterContent { set { centerBlockControl.Visible = false; } unset { centerBlockControl.Visible = true; } setNotFound { centerBlockControl.Visible = null; }
Admin
Best comment yet.
Admin
@Override public String toString() { return ((Object) this).toString(); }
Perheps its someone who do not want to expose internals of certain subclass of classes that implements Serializable?
Admin
There's at least some logic behind the toString() example: in C++ (at least back in the 90s), one could, using casts, force a method call to use the method implementation from superclass rather than the actual instance class of the object itself. It looked to me like that was the author's intent.
Of course, in Java that won't work at all and produces the infinite loop we all see easily...
Admin
I think the problem is the person who wrote it, wrote a bad comment (possibly because he knew an undefined value failed {or at least new this would fail at times} but didn't really understand why).
Until reading comments, I assumed he meant to make sure that the value was null if it should be (otherwise it can remain whatever it is).
I'm surprised there seem to be a lot of Java people commenting, who really jump up and down about how silly it is.... Isn't this (sort of) why .equals() was introduced -> = (or == or whatever Mr Bunny uses) compare the actual object, .equals() compares some measure the programmer has defined for the equality of objects...
As some hve pointed out, this is why PHP (and possibly others) have ===
Admin
'They' may be a programmer fresh out of school. He finds that there is a problem (he may even realise that it is somehow linked to passing a value through for the first time {ie when unitialised}), and finds that setting it to NULL as in the example seems to work.
He doesn't care why, he has spent 3 days tracking down a bug that (even as he thinks about it) makes no sense, because like so many others here, it seems obvious that null is null. Possibly, he even passes on his story how null is not always null to other employees. As far as he is concerned, however, the code works. (Perhpas this is the actual WTF)
Admin
@SCB Do you not realise, my son, that bad programming is optimised by the compiler these days. There is no need for humble developers to try to reduce the number of statements, the Compiler is generally better at it for simple things like this.
Admin
FTFY
Admin
The unreal nulls often come from empty strings or 0 collected from user input... the variable name "googleId" suggests to me that the were using either a Google Analytics ID, or a Google API key, which a user had to input; if the user left the field blank, it would be an empty string, which in JavaScript compares equal to null, 0, and boolean false.
See also http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN
For those who are saying that the way it was expressed is TRWTF, be aware that while it may appear weird to those of us coming from a C/C++/Java world, it's essentially idiomatic in the PHP and JavaScript world and would not gather a second look or a question.
If the code in question is in one of the languages with strong types and strict nulls, then it is a WTF, probably created by a programmer who moved across from one of the "liberal null" languages.
Admin
How about this for a wtf: renaming a whole bunch of variables from camel toe-case to some other scheme. The code is under revision control, so forget diffing versions of this code before and after the camel toe adjustment and easily finding code changes.
Avoid formatting and/or mass renaming edits on files under source code control. If you must do it, don't do it simultaneously with other edits.
Admin
"The Bactrian Camel (Camelus bactrianus) is a large even-toed ungulate"
Seems like toes really are important when it comes to camels...