Convoluted toString, Interesting Comments, and More

« Return to Article
  • Josephus 2010-05-19 09:05
    stories about Russians? this would be good as an audio reading...

    just saying..
  • Ocson 2010-05-19 09:08
    After a day off, Alex lets loose with an explosion of WTF. Well played sir.
  • joeyadams 2010-05-19 09:09
    Josephus:
    stories about Russians? this would be good as an audio reading...

    just saying..


    I suppose all the code samples could be read in a Russian accent.
  • @Deprecated 2010-05-19 09:12
    "The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

    googleId = googleId == null ? null : googleId; // ensure really null


    Dammit, now I have to go back through all my unit tests and check for really null. And then change my var names to camel toe.
  • djmaze 2010-05-19 09:15

    public static bool IsInfiniteLoop()
    {
    return !IsFiniteLoop();
    }

    public static bool IsFiniteLoop()
    {
    return !IsInfiniteLoop();
    }

    void definiteCrash()
    {
    IsInfiniteLoop();
    }
  • frits 2010-05-19 09:15
    /***        REVISION: 6.9                                   *** 
    
    *** DATE: 6 June 2006 ***
    *** PROGRAMMER: Fedor Emelianenko ***
    *** DESCRIPTION: Upgraded all camel toe vars to ***
    *** moose knuckle case. ***/

  • FeepingCreature 2010-05-19 09:18
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.
  • Markp 2010-05-19 09:19
    The toString() snippet is an even more direct example of an infinite loop.
  • anonymous coward 2010-05-19 09:22
    FeepingCreature:
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


    Then it would still be a WTF for using operator overloading when it doesn't make sense (which is almost always. The only places where I can see operator overloading used sensibly is in math libraries)
  • xyzzy 2010-05-19 09:23
    It would also make sense in PHP, if you want to turn "something like null" (false, 0, etc) into "really and truly is null".
  • Drew 2010-05-19 09:24
    frist = frist != frist ? frist : frist; // ensure really frist
  • Michael Mol 2010-05-19 09:24
    A little redundant, and slightly inconsistent, but this kind of thing helps me stay insane, and therefore continue to enjoy my job:
    iFoundIt = someSet.find(val);
    
    someSet.erase(iRemove);

    (No, we don't normally use i as a prefix for integers, why do you ask?)

    (captcha: "paratus", as in, "Paratus! Paratus! Free Paratus!")
  • DOA 2010-05-19 09:25
    "googleId = googleId == null ? null : googleId; // ensure really null"

    I think I have a brain haemorrhage

  • Anonymouse 2010-05-19 09:27
    Too lazy to verify with actual tests, but wouldn't the toString() one just get back the default toString() method if a parent class defined a custom one? Also, the googleId snippet looks valid for languages where values can be equal to null w/o acutally being null.
  • sink 2010-05-19 09:29
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().
  • Lee K-T 2010-05-19 09:29
    Why does he give names to his Camel's toes?
  • DES 2010-05-19 09:31
    FeepingCreature:
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


    No, it will never make sense. What it actually does is:

    googleId = googleId
  • Anon 2010-05-19 09:32
    No. Java will always invoke the most specific implementation of a method for a given object instance. Attempting to cast an object does not change which method implementation is invoked.
  • Severity One 2010-05-19 09:37
    recursion

    re·cur·sion [ri-kur-zhuhn]

    See: recursion
  • @Deprecated 2010-05-19 09:38
    r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

    cleaned code, modified function format_for_rtf . no more
    numbered key to access video array elements, renamed all
    camel toe vars, applied consistent coding formating


    I like how all those changes were applied to 1 line. Wow!
  • Kris 2010-05-19 09:44
    No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

    [pre]
    if (googleId === undefined)
    googleId = null;
    [/pre]

    The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.
  • parquet 2010-05-19 09:44
    <?php
    $googleId = 0;
    var_dump($googleId);
    $googleId = $googleId == null ? null : $googleId;
    var_dump($googleId);

    outputs

    int(0)
    NULL

    *shrug*.
  • Core Xii 2010-05-19 09:45
    DES:
    No, it will never make sense. What it actually does is:

    googleId = googleId

    No, he's right. For example in PHP, with loose comparison (==), false returns true when compared to null. But when _assigned_ to null, it'll be of type null.

    So this code is entirely legit, IF the assumed conditions hold true.

    See here for reference:
    http://www.php.net/manual/en/types.comparisons.php
    false, 0, an empty array and an empty string all == null.
  • SCB 2010-05-19 09:46
    @Deprecated:
    r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

    cleaned code, modified function format_for_rtf . no more
    numbered key to access video array elements, renamed all
    camel toe vars, applied consistent coding formating


    I like how all those changes were applied to 1 line. Wow!

    He forgot to add in the comment
    "removed all carriage returns"
  • blah 2010-05-19 09:47
    DES:
    No, it will never make sense. What it actually does is:

    googleId = googleId

    Not if the language is javascript and googleId was undefined. It's probably still a WTF but there are differences (in javascript):

    js> undefined == null
    true
    js> Number(null)
    0
    js> Number(undefined)
    NaN
  • junkpile 2010-05-19 09:48
    @Deprecated:
    r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

    cleaned code, modified function format_for_rtf . no more
    numbered key to access video array elements, renamed all
    camel toe vars, applied consistent coding formating


    I like how all those changes were applied to 1 line. Wow!


    Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...
  • Sir Read-a-Lot 2010-05-19 09:50
    Lee K-T:
    Why does he give names to his Camel's toes?

    Why does a Russian have a camel in the first place?

    *disclamer: this comment is not meant to imply in any way that Russians are in some way incapable or undeserving of having camels. It's just... well... nevermind.


    CAPTCHA: nulla - any null that hasn't yet been checked to make sure it really is null.
  • Aris 2010-05-19 09:54
    As another reader told, a method is always executed using the virtual pointer, whatever the object is casted to. The only exception is the method used on super.

    This looks like java written by a C++ guy. And I really think java is better that C++ in this regard.
  • IronMensan 2010-05-19 09:57
    anonymous coward:
    FeepingCreature:
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


    Then it would still be a WTF for using operator overloading when it doesn't make sense (which is almost always. The only places where I can see operator overloading used sensibly is in math libraries)


    I've defined += on container classes and I've defined == on a few classes
  • Steve H. 2010-05-19 09:57
    My initial thought on the last one was that someone was trying to use a variable that should have been declared volatile. Then I looked a little more carefully and realized it was more WTF than I initially thought.

    Correct me if I'm wrong, but rewriting that code to be more readable produces this functionality:

    if (googleId == null) {
    googleId = null;
    }
    else {
    googleId = googleId;
    }

    So contrary to the comment, it doesn't even ensure that googleId is null at all, as opposed to REALLY null (a comment I'd expect with a WTF line like googleId = googleId = null;)
  • Jake Boxer 2010-05-19 10:00
    In our Android app, we deal with a bunch of JSON parsing. Have a look at JSONObject.NULL:

    http://developer.android.com/intl/de/reference/org/json/JSONObject.html#NULL

    Since JsonObject.NULL.toString evaluates to "null" (even though JsonObject.NULL == null returns true), this was causing us to end up with "null" in a bunch of our views. We ended up wrapping it in a method that converts it to real null, just like this guy is doing in the last one.
  • enfiskutensykkel 2010-05-19 10:09
    sink:
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().


    Nope, not in Java.
  • @Deprecated 2010-05-19 10:13
    junkpile:
    @Deprecated:
    r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

    cleaned code, modified function format_for_rtf . no more
    numbered key to access video array elements, renamed all
    camel toe vars, applied consistent coding formating


    I like how all those changes were applied to 1 line. Wow!


    Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...


    Sorry, didn't realize this site was "Curious Perversions in Information Technology, But No Stupid Jokes Please"...


  • bl@h 2010-05-19 10:17
    Since when are camels native to Russia?

    captcha:nulla -> Make sure it is really nulla!
  • Daniel 2010-05-19 10:18
    Then he'd test for NULL, not null (which is a reserved keyword in Java, so you can't possibly refer to something else). I still find the JavaScript explanation the most likely.
  • snoofle 2010-05-19 10:18
    I'm a consultant, and I've never, ever done a check for really null.

    Now I have to go back and redo all the Java code I've written in the past 15 years. Wonderful!
  • Whiskey, Eh? 2010-05-19 10:24
    void myLifeStory()
    {
    iReceiveHead = false;
    iReceiveTail = false;

    /* ... sigh..... */
    }
  • junkpile 2010-05-19 10:26
    @Deprecated:
    junkpile:
    @Deprecated:
    r22795 | t-------- | 2010-05-10 16:06:35 -0400 | 1 line

    cleaned code, modified function format_for_rtf . no more
    numbered key to access video array elements, renamed all
    camel toe vars, applied consistent coding formating


    I like how all those changes were applied to 1 line. Wow!


    Yea, because they couldn't possibly have committed multiple resources with the same comment at the same time...


    Sorry, didn't realize this site was "Curious Perversions in Information Technology, But No Stupid Jokes Please"...




    Sorry, I'm not convinced that it was a purposeful stupid joke...
  • DCRoss 2010-05-19 10:26
    You have not experienced Kernighan and Ritchie until you have read them in the original Russian.
  • Callin 2010-05-19 10:29
    public static bool IsNotNotNotEmpty(string value)
    {
    return !IsNotNotEmpty(value);
    }
  • @Deprecated 2010-05-19 10:36
    junkpile:

    Sorry, I'm not convinced that it was a purposeful stupid joke...


    Hmmm, yes, they rarely are... Hopefully this will help to sort it out:

    "If, in reading the following pages, you are uncertain as to whether a specific statement is meant seriously or not, simply apply this rule of thumb: If the statement makes you consider filing a lawsuit, I was kidding!"

    ~ Dave Barry
  • fubar 2010-05-19 10:39
    As already pointed out, strict comparison is required in PHP.

    <?php
    $googleId = null;
    var_dump($googleId);

    $googleId = 0;
    var_dump($googleId);

    $googleId = ($googleId === null) ? null : $googleId;
    var_dump($googleId);
    ?>

    Output:
    NULL
    int(0)
    int(0)
  • Just an ordinary code monkey 2010-05-19 10:49
    Kris:
    No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

    if (googleId === undefined)
    googleId = null;

    The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.


    undefined is certainly a possible reason for this code, but he doesn't cater for it, which the comment suggests he intends to. I don't think undefined is meant to slip through the net in this code, although it does...

    I think people are getting carried away on it because to make sure it's really null, most people would just do the following...

    googleId = null;

    No..?
  • ChrisB 2010-05-19 10:50
    Our company uses a similar variation of Hungarian Notation to name variables. I did get to have a chuckle recently at some permissions checking code (where strings are used to denote the permission type)...
  • Jumble 2010-05-19 10:53
    Do PHP users things that two WTFs make an acceptable piece of code?
  • junkpile 2010-05-19 10:54
    @Deprecated:
    junkpile:

    Sorry, I'm not convinced that it was a purposeful stupid joke...


    Hmmm, yes, they rarely are... Hopefully this will help to sort it out:

    "If, in reading the following pages, you are uncertain as to whether a specific statement is meant seriously or not, simply apply this rule of thumb: If the statement makes you consider filing a lawsuit, I was kidding!"

    ~ Dave Barry


    Hmmm, indeed. I wasn't kidding, but if quoting someone else helps you cover your apparently obvious stupid joke you were trying to convey, well done...
  • Tony 2010-05-19 10:54
    public bool HideCenterContent
    {
    set
    {
    centerBlockControl.Visible = false;
    }
    }


    This should really be a Get not a set. What were they thinking! With a get you could go object.HideCentercontent!
    But with a set, it would have to be object.HideCenterContent = some value. Crazy developers, they should really know better.
  • Quirkafleeg 2010-05-19 11:02
    Core Xii:
    But when _assigned_ to null
    … you get a compile-time error.
  • Quirkafleeg 2010-05-19 11:07
    SCB:
    @Deprecated:
    I like how all those changes were applied to 1 line. Wow!
    He forgot to add in the comment
    "removed all carriage returns"
    That wouldn't make any difference. One line before, one line afterwards.

    Now, removing all line feeds – that would make a difference…
  • Henning Makholm 2010-05-19 11:09
    public bool HideCenterContent {
    
    set {
    centerBlockControl.Visible = false;
    }
    unset {
    centerBlockControl.Visible = true;
    }
    }
  • wtf 2010-05-19 11:11
    Just an ordinary code monkey:
    Kris:
    No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

    if (googleId === undefined)
    googleId = null;

    The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.


    undefined is certainly a possible reason for this code, but he doesn't cater for it, which the comment suggests he intends to. I don't think undefined is meant to slip through the net in this code, although it does...

    I think people are getting carried away on it because to make sure it's really null, most people would just do the following...

    googleId = null;

    No..?


    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
  • dkf 2010-05-19 11:12
    bl@h:
    Since when are camels native to Russia?
    Hah! The range of the Bactrain Camel is almost into Russia even these days, so it's entirely possible that there have been native camels in (Siberian) Russia within the past 200 years.
  • @Deprecated 2010-05-19 11:13
    junkpile:
    @Deprecated:
    junkpile:

    Sorry, I'm not convinced that it was a purposeful stupid joke...


    Hmmm, yes, they rarely are... Hopefully this will help to sort it out:

    "If, in reading the following pages, you are uncertain as to whether a specific statement is meant seriously or not, simply apply this rule of thumb: If the statement makes you consider filing a lawsuit, I was kidding!"

    ~ Dave Barry


    Hmmm, indeed. I wasn't kidding, but if quoting someone else helps you cover your apparently obvious stupid joke you were trying to convey, well done...


    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...
  • Core Xii 2010-05-19 11:13
    Just an ordinary code monkey:
    I think people are getting carried away on it because to make sure it's really null, most people would just do the following...

    googleId = null;

    No..?

    He's not making sure it's really null. He's making sure it's really null if it evaluates to null using loose comparison. So if it's NOT equal to null (not false, 0, empty string, etc.) nothing changes. But if it DOES equal null, he makes sure its type is actually null!

    Quirkafleeg:
    Core Xii:
    But when _assigned_ to null
    … you get a compile-time error.

    I meant of course when null is assigned to IT. Excuse my grammar.
  • evilspoons 2010-05-19 11:14
    junkpile:
    Hmmm, indeed. I wasn't kidding, but if quoting someone else helps you cover your apparently obvious stupid joke you were trying to convey, well done...


    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.
  • SenTree 2010-05-19 11:34
    Sir Read-a-Lot:
    Lee K-T:
    Why does he give names to his Camel's toes?
    Why does a Russian have a camel in the first place?
    bl@h:
    Since when are camels native to Russia?

    en.wikipedia.org/wiki/Bactrian_Camel

    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'.
  • DrStevens 2010-05-19 11:36
    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).
  • Markp 2010-05-19 11:43
    sink:
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().

    No, it doesn't. It doesn't change a damned thing. It's a recursive, non-terminating call exactly equivalent to this:

    this.toString()
  • qbolec 2010-05-19 11:47
    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.
  • IChrisI 2010-05-19 11:50
    Whiskey, Eh?:
    void myLifeStory()
    {
    iReceiveHead = false;
    iReceiveTail = false;

    /* ... sigh..... */
    }

    Good show, sir.
  • null 2010-05-19 12:15
    googleId = googleId == null ? null : googleId; // ensure really null


    The googles... they do nothing!

    captcha: nulla
  • Protector one 2010-05-19 12:16
    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?
  • wtf 2010-05-19 12:25
    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.

  • SCB 2010-05-19 12:28
    Protector one:
    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?

    It still contains a redundant assignment of googleId to googleId.
    Surely it would be more efficient as something like:
    if (googleId==null) googleId=null;
  • wtf 2010-05-19 12:37
    SCB:

    It still contains a redundant assignment of googleId to googleId.
    Surely it would be more efficient as something like:
    if (googleId==null) googleId=null;


    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.
  • Massive Debt 2010-05-19 12:38
    public static bool IsNotEmpty(string value)
    {
    return !IsEmpty(value);
    }

    public static bool IsEmpty(string value)
    {
    return !IsNotEmpty(value);
    }

    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).
  • OldPeter 2010-05-19 12:39
    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.
  • frits 2010-05-19 12:56
    OldPeter:
    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.


    I was thinking it was a corruption of "camel case".
  • FuBar 2010-05-19 12:59
    null:
    The googles... they do nothing!

    Win


  • eros 2010-05-19 13:03
    OldPeter:
    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.

    It is amazing how you try to justify it.
    The Russian obviously meant "camel case."
    He was probably more familiar with the phrase "camel toe" than the phrase "camel case" and made an honest translation mistake.
  • Erasmus Darwin 2010-05-19 13:09
    Protector one:
    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?


    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:

    googleId = googleId == null ? null : googleId; // ensure really null

    versus:

    // Ensure real null value for things that test null (undefined, etc.)
    if (googleId == null) { googleId = null; }


    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.
  • Abdiel 2010-05-19 13:23
    Henning Makholm:
    public bool HideCenterContent {
    
    set {
    centerBlockControl.Visible = false;
    }
    get {
    centerBlockControl.Visible = true;
    }
    }


    FTFY.

    And I thought I was abusing properties when I made the getter read from a stream...
  • peedy 2010-05-19 13:58
    @Deprecated:
    "The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

    googleId = googleId == null ? null : googleId; // ensure really null


    Dammit, now I have to go back through all my unit tests and check for really null. And then change my var names to camel toe.


    Oh wow, win. That was one of the best comments I've read in a while. Well played.
  • Mcoder 2010-05-19 14:01
    qbolec:
    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.


    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.
  • EvanED 2010-05-19 14:07
    anonymous coward:
    FeepingCreature:
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


    Then it would still be a WTF for using operator overloading when it doesn't make sense (which is almost always. The only places where I can see operator overloading used sensibly is in math libraries)


    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.
  • bior 2010-05-19 14:11
    It's only a problem when dealing with large values of null.
  • Paula 2010-05-19 14:31
    1.) Fix camel toe.
    2.) ?????
    3.) Profit!
  • Dirty0ldMan 2010-05-19 14:52
    Paula:
    1.) Fix camel toe.
    Please don't. Unless I can watch.

    2.) ?????
    Oh. Maybe that's where me watching comes in.

    3.) Profit!
    Yup.
  • Protector one 2010-05-19 15:35
    E. Darwin, your point is well seen. I guess elaborating on kookyness is always a good idea.
  • lolwtf 2010-05-19 15:52
    The Brain was a consultant that was with us for a while working in a cubicle far away from the rest of the team," writes Enoch Needles, "we didn't socialize with him, and we weren't quite sure what he was doing
    My guess is he was a lab mouse trying to take over the world. That code looks more like Pinky though...
  • lolwtf 2010-05-19 15:53
    public String TWDTFComment
    {
    set
    {
    comment.text = "frist";
    }
    }
  • Dan 2010-05-19 15:53
    "The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

    googleId = googleId == null ? null : googleId; // ensure really null


    Seems to me that if this were a language where more than one thing can be equivalent to null, he wouldn't have to try to justify the pattern. Just demonstrate it the way the JS and PHP commentators already did.
  • Dan 2010-05-19 16:06
    Dan:
    "The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

    googleId = googleId == null ? null : googleId; // ensure really null


    Seems to me that if this were a language where more than one thing can be equivalent to null, he wouldn't have to try to justify the pattern. Just demonstrate it the way the JS and PHP commentators already did.


    But I see no $'s, so it's not PHP.

    Maybe the guy came from DRAM production. Have to keep refreshing the value of the variable :P
  • qbolec 2010-05-19 16:11
    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.
  • Evil Code Monkey 2010-05-19 16:26
    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; }
    }
  • AnOldRelic 2010-05-19 16:31
    Sir Read-a-Lot:
    Lee K-T:
    Why does he give names to his Camel's toes?

    Why does a Russian have a camel in the first place?


    Because the unicycle was in the shop?
  • Peter 2010-05-19 17:07
    Severity One:
    recursion

    re·cur·sion [ri-kur-zhuhn]

    See: recursion

    Cute, but that's not recursion either.
  • Fedaykin 2010-05-19 18:28
    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).
  • Simon 2010-05-19 18:51
    eros:
    He was probably more familiar with the phrase "camel toe" than the phrase "camel case" and made an honest translation mistake.


    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 :)
  • NorgTheFat 2010-05-19 19:21
    Henning Makholm:
    public bool HideCenterContent {
    
    set {
    centerBlockControl.Visible = false;
    }
    unset {
    centerBlockControl.Visible = true;
    }
    }


    Don't forget to check for tri-states...

    HideCenterContent {
    set {
    centerBlockControl.Visible = false;
    }
    unset {
    centerBlockControl.Visible = true;
    }
    setNotFound {
    centerBlockControl.Visible = null;
    }
  • SQLDave 2010-05-19 20:10
    bior:
    It's only a problem when dealing with large values of null.


    Best comment yet.
  • Cheong 2010-05-19 21:13
    @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?
  • Joe Shelby 2010-05-19 21:49
    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...
  • Johnno 2010-05-19 21:51
    Just an ordinary code monkey:
    Kris:
    No, there are certainly cases where it makes sense. Namely if it were JavaScript, which I suspect is the case. In JavaScript, undefined == null, but undefined !== null. So the line is actually equivalent to:

    if (googleId === undefined)
    googleId = null;

    The above would have certainly have been clearer, but I strongly suspect that it was, in fact, the intent.


    undefined is certainly a possible reason for this code, but he doesn't cater for it, which the comment suggests he intends to. I don't think undefined is meant to slip through the net in this code, although it does...

    I think people are getting carried away on it because to make sure it's really null, most people would just do the following...

    googleId = null;

    No..?


    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 ===
  • Bilongda Mick 2010-05-19 22:00
    qbolec:
    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.


    '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)
  • Sage 2010-05-19 22:03
    wtf:
    SCB:

    It still contains a redundant assignment of googleId to googleId.
    Surely it would be more efficient as something like:
    if (googleId==null) googleId=null;


    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.


    @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.
  • facecious 2010-05-19 22:11
    NorgTheFat:
    Henning Makholm:
    public bool HideCenterContent {
    
    set {
    centerBlockControl.Visible = false;
    }
    unset {
    centerBlockControl.Visible = true;
    }
    }


    Don't forget to check for tri-states...

    HideCenterContent {
    set {
    centerBlockControl.Visible = false;
    }
    unset {
    centerBlockControl.Visible = true;
    }
    setNotFound {
    centerBlockControl.Visible = (centerBlockControl.Visible == null?centerBlockControl.Visible:null);
    }


    FTFY
  • random_garbage 2010-05-19 22:32
    qbolec:
    sorry for repeating, but TRWTF is they did not debug the source of these "unreal" null, and choose to overwrite it with real null.


    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.

  • AntiQuercus 2010-05-20 01:36
    Fedaykin:
    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).


    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.

  • Lee K-T 2010-05-20 01:49
    SenTree:
    Sir Read-a-Lot:
    Lee K-T:
    Why does he give names to his Camel's toes?
    Why does a Russian have a camel in the first place?
    bl@h:
    Since when are camels native to Russia?

    en.wikipedia.org/wiki/Bactrian_Camel

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


    "The Bactrian Camel (Camelus bactrianus) is a large even-toed ungulate"

    Seems like toes really are important when it comes to camels...
  • SlyEcho 2010-05-20 02:44
    If it was Javascript I would write it:

    googleId = googleId || null;
    It ensures googleId is null if it was undefined, null or '' previously. Of course if the intended use for the null value was something like this later:

    if (googleId != null) { ... }
    Then the first line is not needed as you can just simply write:

    if (googleId) { ... }

  • SenTree 2010-05-20 04:22
    googleId = googleId == null ? null : googleId; // ensure really null
    You have to be really certain that googleId is really null, otherwise it might override googleSuperego.

    Monsters from the googleId might then destroy the 'Don't be evil' mantra.
  • Laser-Opto the Supervillain 2010-05-20 04:22
    goggleEyed = goggleEyed == null ? null : goggleEyed; // ensure really dull

    FTFY
  • TbK 2010-05-20 05:27
    I am new to tdwtf, but I like it.

    Just wanted to mention that most of this horrible code in this issue is optimized by the compiler anyway, isn't it?
  • Pot-ah-to Pot-ay-to 2010-05-20 06:37
    TbK:
    I am new to tdwtf, but I like it.

    Just wanted to mention that most of this horrible code in this issue is optimized by the compiler anyway, isn't it?


    Nope. Most of it just blows up in the user's face.
  • Andrew in a Suit 2010-05-20 08:02
    "The sad part about this code," Ramin writes," is that its author actually tries to justify this pattern. "

    googleId = googleId == null ? null : googleId; // ensure really null


    The sad part about some broken VMs I can name, possibly still including PHP, is that the pattern is justifiable.
  • Harrow 2010-05-20 12:03
    cAMELtOEvARS
    cONSISTENTcODEfORMATTING
    eTC.

    -hARROW.
  • AHB 2010-05-20 16:54
    This reminds me of a CS professor I had in college. He was from Germany and had a thick accent. His grammar was understandable, but sometimes hilarious.

    One day he was giving a lecture on probability:

    "OK, say we flip ze coin. Now, say I want head." I smile at one of my classmates. A few minutes later "OK, so all I want is head." Now I snicker a little and I'm having trouble not laughing. I look around at the rest of the 19 year olds in the classroom and the situation is dire, everyone is about to bust out laughing. After he says a couple more variations of "All I want is head" he realizes that something's up and next time it's, "so now all I want is tail" and everybody's laughing out loud.

    Another time he was talking about dynamic programming and the problem of loading packages of different sizes into a truck. He's trying to call the algorithm the packer but it comes out as pecker. He brought the house down once he started talking about using recursion, asking his "little brother" to do some of the work for him: "SO now I'm going to use my little brother's pecker..."
  • Eternal Density 2010-05-20 22:17
    djmaze:

    public static bool IsInfiniteLoop()
    {
    return !IsFiniteLoop();
    }

    public static bool IsFiniteLoop()
    {
    return !IsInfiniteLoop();
    }

    void definiteCrash()
    {
    IsInfiniteLoop();
    }
    Hmm, how about this?
    public static bool IsInfiniteLoop()
    
    {
    try
    {
    return !IsFiniteLoop();
    }
    catch (StackOverflowException)
    {
    return true;
    }
    }

    public static bool IsFiniteLoop()
    {
    try
    {
    return !IsInfiniteLoop();
    }
    catch (StackOverflowException)
    {
    return !true;
    }
    }
  • iMalc 2010-05-21 02:08
    Camel Case is great until you start writing methods with names such as the clbuttic:
    bool PenIsUp() { return !PenIsDown(); }
    bool PenIsDown() { return !PenIsUp(); }
  • Anonymous 2010-05-21 05:12
    Anyone who can't see what the GoogleID comment is doing needs to brush up on some modern languages. I could immediately determine the intention of that code and why it was doing what it was doing.

    Like it or not, loose comparison is becoming extremely common thanks to languages like PHP and javascript. Yes, the real WTF may be the language itself, and it may be stupid, but that doesn't change the fact that many modern languages are heading that direction and you need to at least be able to interpret code that way in your head when necessary, or start preparing for retirement.
  • methinks 2010-05-21 07:14
    As usual, the "Real WTF" (TM) lies in the comments:

    Most commenters obviously did not get that

    1) "Camel toe" is a mix-up with "camel case", a naming convention for source code identifiers, in which adjacent words in otherwise completely lowercase names start with a capital letter to increase readability:
    thisIsACamelCasedIdentifier
    "Camel case" thus pertains to the "humps" inside such names.

    2) "Camel toe" is something completely different and quite a well known meme on "teh internets":
    http://www.urbandictionary.com/define.php?term=camel+toe

    The russian guy was obviously thinking about something else when writing this ;o)

    Remember, the internet is for p0rn! ;o)
    http://www.youtube.com/watch?v=T-TA57L0kuc
  • jerk_programmer 2010-05-21 09:25
    DES:
    FeepingCreature:
    The googleId one _might_ make sense if the language supports overloading == and googleId is an object defined to sometimes return true on equality to null.


    No, it will never make sense. What it actually does is:

    googleId = googleId

    Incorrect.

    Perl:
    http://stackoverflow.com/questions/137487/null-vs-false-vs-0
    Javascript:
    http://www.bloggingdeveloper.com/post/JavaScript-null-vs-undefined-The-Difference-between-null-and-undefined.aspx

    and so on, it is very common in dynamically typed languages that 2 values may be equal under == but have different types and be not equal under some other operator such as ===
  • wulf 2010-05-21 09:27
    sink:
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().



    No. It doesn't matter what super or interface type you choose to "view" an object as, it matters what specific type the object actually is. That's the whole point, really. Your way would make inheritance completely useless.
  • sink 2010-05-21 11:38
    Right! I turned crazy by trying to force sanity into that code.
  • sink 2010-05-21 11:39
    wulf:
    sink:
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().



    No. It doesn't matter what super or interface type you choose to "view" an object as, it matters what specific type the object actually is. That's the whole point, really. Your way would make inheritance completely useless.


    Right! I turned crazy by trying to force sanity into that code
  • nothanks 2010-05-24 09:02
    methinks:
    As usual, the "Real WTF" (TM) lies in the comments:

    Most commenters obviously did not get that
    [...]

    Whoosh!
  • the_joke_explained 2010-05-26 10:20
    http://en.wikipedia.org/wiki/Cameltoe
  • MSCW 2010-05-31 07:27
    IronMensan:


    I've defined += on container classes and I've defined == on a few classes


    That doesn't mean that your operators makes sense just because you defined them.
    Who are you, after all, russian coder?
  • MSCW 2010-05-31 07:28
    bl@h:
    Since when are camels native to Russia?


    Since 1917 when we conquered Asia steppes
  • WWWWolf 2010-06-08 04:32
    VB6?

    Birds?

    ::evil swamplike flashbacks::
  • zx 2010-06-08 11:49
    a question to native speakers: how would you rewrite the Russian guy's comment in a proper way?
  • apoc9 2011-11-07 05:45
    No, It doesn't.

    super.toString() // call method toString defined in parent class of this instance
    ((Object) this).toString() // this is Object & call method toString on this instance