• Josephus (unregistered)

    stories about Russians? this would be good as an audio reading...

    just saying..

  • Ocson (unregistered)

    After a day off, Alex lets loose with an explosion of WTF. Well played sir.

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

    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.

  • (cs)
    public static bool IsInfiniteLoop()
    {
        return !IsFiniteLoop();
    }
    
    public static bool IsFiniteLoop()
    {
        return !IsInfiniteLoop();
    }
    
    void definiteCrash()
    {
        IsInfiniteLoop();
    }
    
  • (cs)
    /***        REVISION: 6.9                                   *** 
     ***            DATE: 6 June 2006                           *** 
     ***      PROGRAMMER: Fedor Emelianenko                     *** 
     ***     DESCRIPTION: Upgraded all camel toe vars to        *** 
     ***                  moose knuckle case.                   ***/
    
    
  • FeepingCreature (unregistered)

    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.

  • (cs)

    The toString() snippet is an even more direct example of an infinite loop.

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

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

    frist = frist != frist ? frist : frist; // ensure really frist

  • Michael Mol (unregistered)

    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!")

  • (cs)

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

    I think I have a brain haemorrhage

  • Anonymouse (unregistered)

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

    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().

  • Lee K-T (unregistered)

    Why does he give names to his Camel's toes?

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

    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.

  • (cs)

    recursion

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

    See: recursion

  • @Deprecated (unregistered)
    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 (unregistered) in reply to DES

    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 (unregistered) in reply to DES
    <?php $googleId = 0; var_dump($googleId); $googleId = $googleId == null ? null : $googleId; var_dump($googleId); outputs int(0) NULL *shrug*.
  • Core Xii (unregistered) in reply to DES
    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.

  • (cs) in reply to @Deprecated
    @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 (unregistered) in reply to DES
    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 (unregistered) in reply to @Deprecated
    @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 (unregistered) in reply to Lee K-T
    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 (unregistered) in reply to sink

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

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

  • Steve H. (unregistered)

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

    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.

  • (cs) in reply to sink
    sink:
    ((Object)this).toString executes the implementation of Object instead of extented class. Like in super.super....toString().

    Nope, not in Java.

  • @Deprecated (unregistered) in reply to junkpile
    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"...

    [image]
  • bl@h (unregistered)

    Since when are camels native to Russia?

    captcha:nulla -> Make sure it is really nulla!

  • Daniel (unregistered) in reply to Jake Boxer

    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.

  • (cs)

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

    void myLifeStory() { iReceiveHead = false; iReceiveTail = false;

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

  • junkpile (unregistered) in reply to @Deprecated
    @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"...

    [image]

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

  • (cs) in reply to joeyadams

    You have not experienced Kernighan and Ritchie until you have read them in the original Russian.

  • (cs)

    public static bool IsNotNotNotEmpty(string value) { return !IsNotNotEmpty(value); }

  • @Deprecated (unregistered) in reply to junkpile
    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 (unregistered)

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

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

    Do PHP users things that two WTFs make an acceptable piece of code?

  • junkpile (unregistered) in reply to @Deprecated
    @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 (unregistered)
    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 (unregistered) in reply to Core Xii
    Core Xii:
    But when _assigned_ to null
    … you get a compile-time error.
  • Quirkafleeg (unregistered) in reply to SCB
    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 (unregistered)
    public bool HideCenterContent {
        set {
            centerBlockControl.Visible = false;
        }
        unset {
            centerBlockControl.Visible = true;
        }
    }

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

Log In or post as a guest

Replying to comment #309082:

« Return to Article