• wtf (unregistered) in reply to Just an ordinary code monkey
    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

  • (cs) in reply to bl@h
    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 (unregistered) in reply to junkpile
    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 (unregistered) in reply to Just an ordinary code monkey
    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 (unregistered) in reply to junkpile
    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.

  • (cs) in reply to Sir Read-a-Lot
    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 (unregistered) in reply to FeepingCreature

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

  • (cs) in reply to sink
    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 (unregistered)

    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 (unregistered) in reply to Whiskey, Eh?
    Whiskey:
    void myLifeStory() { iReceiveHead = false; iReceiveTail = false;

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

    Good show, sir.

  • null (unregistered)
    googleId = googleId == null ? null : googleId; // ensure really null

    The googles... they do nothing!

    captcha: nulla

  • Protector one (unregistered)

    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 (unregistered)

    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.

  • (cs) in reply to Protector one
    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 (unregistered) in reply to SCB
    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 (unregistered)
    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 (unregistered)

    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.

  • (cs) in reply to OldPeter
    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 (unregistered) in reply to null
    null:
    The googles... they do nothing!
    Win
  • eros (unregistered) in reply to OldPeter
    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.
  • (cs) in reply to Protector one
    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.

  • (cs) in reply to Henning Makholm
    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 (unregistered) in reply to @Deprecated
    @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.

  • (cs) in reply to qbolec
    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.

  • (cs) in reply to anonymous coward
    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 (unregistered) in reply to snoofle

    It's only a problem when dealing with large values of null.

  • Paula (unregistered)

    1.) Fix camel toe. 2.) ????? 3.) Profit!

  • Dirty0ldMan (unregistered) in reply to Paula
    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 (unregistered) in reply to Erasmus Darwin

    E. Darwin, your point is well seen. I guess elaborating on kookyness is always a good idea.

  • (cs)
    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...
  • (cs)

    public String TWDTFComment { set { comment.text = "frist"; } }

  • Dan (unregistered)
    "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</div></BLOCKQUOTE>
    

    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 (unregistered) in reply to Dan
    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</div></BLOCKQUOTE>
    

    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 (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to Sir Read-a-Lot
    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 (unregistered) in reply to Severity One
    Severity One:
    recursion

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

    See: recursion

    Cute, but that's not recursion either.

  • Fedaykin (unregistered)

    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 (unregistered) in reply to eros
    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 (unregistered) in reply to Henning Makholm
    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; }

  • (cs) in reply to bior
    bior:
    It's only a problem when dealing with large values of null.

    Best comment yet.

  • Cheong (unregistered)

    @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 (unregistered) in reply to Markp

    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 (unregistered) in reply to Just an ordinary code monkey
    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 (unregistered) in reply to qbolec
    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 (unregistered) in reply to wtf
    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 (unregistered) in reply to NorgTheFat
    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

  • (cs) in reply to qbolec
    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 (unregistered) in reply to Fedaykin
    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 (unregistered) in reply to SenTree
    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...

Leave a comment on “Convoluted toString, Interesting Comments, and More”

Log In or post as a guest

Replying to comment #:

« Return to Article