• Ytram (cs)

    Duh.  Obviously an uppercase 1 is !

    2 = @
    3 = #

    You get the picture [:P]

  • Kiriai (unregistered)

    My first thought is that perhaps he is checking if the Ignore Case of an Approval Type Code is a particular case.  Magic numbers sure, bad.

    But somehow I'm guessing that it is a case insensative string compair....

  • dubwai (cs)

    Beyond the obvious but harmless WTF:

    How about a variable to hold secApp.getApprovalTypeCode()?

    And it should be "1".equals(... to avoid null pointer exception, assuming this is Java.

  • DZ-Jay (cs)
    Alex Papadimoulis:

    I suppose one advantage to working with other people's code is that it's a good learning experience. Sometimes you walk away enlightened, "hey, cool! I didn't know you could do that!" Other times the lesson learned is something like, "I swear, if I'm ever this guy's boss, the only thing he'll be allowed to develop with is an Etch-a-Sketch." Jeffrey Johnson was fortunate to learn something a bit closer to the former after looking over his predecessor's code. He still can't believe how naïve he was for never checking for upper and lower case numbers ...

    if (secApp.getApprovalTypeCode().equalsIgnoreCase("1"))
    {
    ...
    }
    else if (secApp.getApprovalTypeCode().equalsIgnoreCase("2"))
    {
    ...
    }

    ...

    else if (secApp.getApprovalTypeCode().equalsIgnoreCase("7"))
    {
    ...
    }


    Well, of course the number does not have upper/lower case.  But he is checking, in case the getApprovalTypeCode return does, duh!

        dZ.

  • ferrengi (cs)

    This functionality is necessary because in the future people will start using lowercase numbers.

  • DZ-Jay (cs) in reply to DZ-Jay
    DZ-Jay:

    Well, of course the number does not have upper/lower case.  But he is checking, in case the getApprovalTypeCode return does, duh!

        dZ.



    Oh, and by the way, don't flame me; it was a joke.

        dZ.
  • Anonymous Coward (unregistered)

    thedailywtf.com is the forum where so-called "masters of their domain" people pore over poor, wasted, (illegal), illogical, unoptimized, lengthy code for hours and offer comments, correct code, thinking that they are the Founders of The WTF? phenomenon, with the ultimate command of their skills.

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    Don't ask why I am wasting time now...

  • x-sol (to lazy to login) (unregistered)

    slow wtf week huh

  • xTMFWahoo (cs) in reply to Ytram
    Ytram:
    Duh.  Obviously an uppercase 1 is !

    2 = @
    3 = #

    You get the picture [:P]

    OMG!  that is funny!
  • David (unregistered) in reply to Anonymous Coward

    Anonymous:

    Don't ask why I am wasting time now...

     

    So why are you wasting your time now?

     

    No, but seriously, how much you want to bet this guy is the writer of today's WTF?  [:P][:P]

  • Tom (unregistered)

    It's probably to tell the difference between 1 and <font size="6">1<font size="3">.</font></font>

  • RayS (cs)

    The numbers in caps:
    ONE!!!!
    TWO!!!!
    ...
    NINE!!!!


    After all, capitals are just shouting, right? I guess what this means is that this program cleverly counts "ONE!!!!" and "1" as equal. Quite an elegant solution.

  • podperson (cs) in reply to RayS

    He probably did it because of bad experiences with uppercase booleans...

  • Devil's advocate (unregistered)

    In Java, (at least last time I checked) equalsIgnorCase performs better than equals.

  • osp70 (cs)

    I think that this is absolutely brillant!

  • dubwai (cs) in reply to Devil's advocate

    Anonymous:
    In Java, (at least last time I checked) equalsIgnorCase performs better than equals.

    How's that?

  • DisturbedSaint (cs) in reply to David
    Anonymous:

    No, but seriously, how much you want to bet this guy is the writer of today's WTF?  [:P][:P]



    I was thinking the exact same thing...

    -ds
  • dubwai (cs) in reply to Anonymous Coward

    Anonymous:
    thedailywtf.com is the forum where so-called "masters of their domain" people pore over poor, wasted, (illegal), illogical, unoptimized, lengthy code for hours and offer comments, correct code, thinking that they are the Founders of The WTF? phenomenon, with the ultimate command of their skills.

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    Don't ask why I am wasting time now...

    There's always some douche-bag that feels the need to waste his time chiding others for wasting theirs.  It's pretty stupid, especially when its's done with a sanctimonious tone like the above.

  • CornedBee (cs) in reply to Devil's advocate
    Anonymous:
    In Java, (at least last time I checked) equalsIgnoreCase performs better than equals.

    That's technically impossible unless the implementation of String.equals is a WTF in itself.
  • Paul Tomblin (unregistered) in reply to dubwai
    dubwai:

    There's always some douche-bag that feels the need to waste his time chiding others for wasting theirs.  It's pretty stupid, especially when its's done with a sanctimonious tone like the above.



    There's always some douche-bag that feels the need to waste his time chiding douche-bags who chide others for wasting their time.  :-)

    ObMontyPython: I know I'm not, and I'm sick and tired of being told that I am.
  • dubwai (cs) in reply to Paul Tomblin
    Anonymous:
    dubwai:

    There's always some douche-bag that feels the need to waste his time chiding others for wasting theirs.  It's pretty stupid, especially when its's done with a sanctimonious tone like the above.



    There's always some douche-bag that feels the need to waste his time chiding douche-bags who chide others for wasting their time.  :-)

    Since I am already an admitted time-waster, your time is wasted writing the above.

  • stevekj (cs)

    Oh oh!  I know!  He should've used a switch statement!

    Right?  Right?

  • Hank Miller (unregistered)

    Thats not funny.    Back in college I once caught myself writing a 9 while pressing really hard on the paper where the 'shift' key would be.   Sadly my pencil didn't understand such notation and produced a 9, not a ( like I obviously wanted...

    I caught this because while looking over my answers some didn't make sense so I was re-doing them carefully.    Fortunately it was one assignment so it didn't cost me a grade, and it gives me this really err... interesting... story to tell.

  • DanielR (unregistered)

    Obviously, we need to replace the type code with inheritance and move this method to the secApp object.

  • Mung Kee (cs) in reply to Devil's advocate
    Anonymous:
    In Java, (at least last time I checked) equalsIgnorCase performs better than equals.


    It doesn't, especially for long Strings.  While equals() does use the instanceof comparison operator, equalsIgnoreCase calls Character.toUpperCase() AND Character.toLowerCase() on every single character of both Strings, unless it finds one that doesn't match.

    if (ignoreCase) {
        char u1 = Character.toUpperCase(c1);
        char u2 = Character.toUpperCase(c2);
        if (u1 == u2) {
            continue;
        }
        if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
            continue;
        }
    }
  • John Stracke (unregistered) in reply to Mung Kee

    This is even worse than you'd think, since Character.to{Upper,Lower}Case() are locale-dependent, which makes them hideously slow.  If you're writing, say, a compiler for a language with case-insensitive identifiers, your best bet is to downcase all identifiers as soon as you see them, rather than doing case-insensitive comparisons all over the place.

  • rbriem (cs) in reply to Anonymous Coward

    Anonymous:
    thedailywtf.com is the forum where so-called "masters of their domain" people pore over poor, wasted, (illegal), illogical, unoptimized, lengthy code for hours and offer comments, correct code, thinking that they are the Founders of The WTF? phenomenon, with the ultimate command of their skills.

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    Don't ask why I am wasting time now...

    "Master of their domains ... hours"? More like "newbies with a clue ... minutes".

    I don't even code in the languages represented here and I see the WTFs right off ...

    OHHHHH. Whoops. I missed the <sarcasm> tag there.

    Never mind.

  • dubwai (cs) in reply to Hank Miller

    Anonymous:
    Thats not funny.    Back in college I once caught myself writing a 9 while pressing really hard on the paper where the 'shift' key would be.   Sadly my pencil didn't understand such notation and produced a 9, not a ( like I obviously wanted...

    Were you on acid?

  • Mister Smith (unregistered) in reply to CornedBee
    CornedBee:
    Anonymous:
    In Java, (at least last time I checked) equalsIgnoreCase performs better than equals.

    That's technically impossible unless the implementation of String.equals is a WTF in itself.

    I think its more of a Java thing. I recall reading that inherited methods are somewhat inefficient in java, in that String.equals() [which overrides Object.equals()] will have a higher overhead than String.equalsIgnoreCase() [because it is only declared for String].
    In practise, it depends on the environment and on the version of java you are using, but equalsIgnoreCase can be faster when dealing with very small (1 or 2 character) strings.

    Even if I misremembered, I don't think such a simple oddity is worthy of being called a WTF. Maybe the code used to be a letter, and they changed them to numbers without changing the code. (Actually, that's probably a Bad Thing in itself, but I wouldn't think it deserves to be a WTF.

    (Wow, my CAPTCHA for today is 'random'... self descriptive spamblocking)

    (except that when I hit "post", it says its wrong. Now its 'image'... self descriptive again)
  • Mung Kee (cs) in reply to John Stracke
    Anonymous:
    This is even worse than you'd think, since Character.to{Upper,Lower}Case() are locale-dependent, which makes them hideously slow.  If you're writing, say, a compiler for a language with case-insensitive identifiers, your best bet is to downcase all identifiers as soon as you see them, rather than doing case-insensitive comparisons all over the place.


    Even simpler than a compiler...any global web application.  At my last company they preached i18n through the whole dev cycle, yet there are ASCII depenedent comparisons all over the app.
  • dubwai (cs) in reply to Anonymous Coward

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.

  • Mung Kee (cs) in reply to dubwai
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns
  • dubwai (cs) in reply to Mister Smith

    Anonymous:
    CornedBee:
    Anonymous:
    In Java, (at least last time I checked) equalsIgnoreCase performs better than equals.

    That's technically impossible unless the implementation of String.equals is a WTF in itself.

    I think its more of a Java thing. I recall reading that inherited methods are somewhat inefficient in java, in that String.equals() [which overrides Object.equals()] will have a higher overhead than String.equalsIgnoreCase() [because it is only declared for String].

    This is nonsense.  Java method lookups go from the most specific up the heirarchy.  Even if the compiler did apply some optimization to equalsIgnoreCase method call, it's going to be miniscule in comparison to extra work required for an equals ignore case comparison.

    Anonymous:

    In practise, it depends on the environment and on the version of java you are using, but equalsIgnoreCase can be faster when dealing with very small (1 or 2 character) strings.

    There are so many myths about Java it's unbelievable.  They seem to have reached this critical mass where they cannot be stopped.

     

  • dubwai (cs) in reply to Mung Kee
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns

    Great link.  The 'Absolver' and 'Chain of Possibilities' really apply to my current work.

  • rsynnott (cs) in reply to xTMFWahoo
    xTMFWahoo:
    Ytram:
    Duh.  Obviously an uppercase 1 is !

    2 = @
    3 = #

    You get the picture [:P]

    OMG!  that is funny!


    Wrong tho; it's obviously region specific. Here, uppercase 2 is '"' and uppercase 3 is '£'. (Incidentally, the caps lock key on some old typewriters was actually a shift lock ;) )
  • JohnO (cs)

    This is certainly the weakest WTF I have seen since I started reading this site.

  • AK (unregistered)

    Not a huge WTF..  on modern machines, with Strings with lengths of one, using the equal instead of the ignoreCase will yield about 0.15 second difference...  For every million call! :P

    1 000 000 iterations:  15ms for equals, 172ms for ignorecase,

    I've seen MUCH worst than this!

  • rsynnott (cs) in reply to AK
    Anonymous:
    Not a huge WTF..  on modern machines, with Strings with lengths of one, using the equal instead of the ignoreCase will yield about 0.15 second difference...  For every million call! :P

    1 000 000 iterations:  15ms for equals, 172ms for ignorecase,

    I've seen MUCH worst than this!


    First, that's no joke in certain cases. Besides that, though... it's just STUPID. The programmer is obviously an idiot doing copy-and-paste with no real understanding.
  • tiro (cs) in reply to Mung Kee
    Mung Kee:

    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    At my current job, from which I have just given my two weeks notice, I was told to "use less classes".  I created a class called ${SomeDomainSpecificGarbage}Adopter.  This was not questioned at code review, and is now a part of our (soon to be their) production code.   Truly a resign pattern in this case, and a WTF to call my own!
  • WTFer (cs) in reply to AK
    Anonymous:
    Not a huge WTF..  on modern machines, with Strings with lengths of one, using the equal instead of the ignoreCase will yield about 0.15 second difference...  For every million call! :P

    1 000 000 iterations:  15ms for equals, 172ms for ignorecase,

    I've seen MUCH worst than this!

    The WTF are not only related to the slowness of the code, but also if the code is idiotic.
  • Mung Kee (cs) in reply to tiro
    tiro:
    Mung Kee:

    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    At my current job, from which I have just given my two weeks notice, I was told to "use less classes".  I created a class called ${SomeDomainSpecificGarbage}Adopter.  This was not questioned at code review, and is now a part of our (soon to be their) production code.   Truly a resign pattern in this case, and a WTF to call my own!


    So it's an Adopter pattern wrapped that will become an Absolver pattern when you're gone.  It's always nice to leave a steaming pile for the next guy.
  • RaolinDarksbane (unregistered) in reply to Mung Kee
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    Oh come on, it is a perfectly cromulent word.
  • dubwai (cs) in reply to dubwai
    dubwai:
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns

    Great link.  The 'Absolver' and 'Chain of Possibilities' really apply to my current work.

    I also see a lot of the Simpleton pattern.

  • dubwai (cs) in reply to RaolinDarksbane
    Anonymous:
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    Oh come on, it is a perfectly cromulent word.

    That means?

  • emptyset (cs) in reply to Hank Miller

    Anonymous:
    Thats not funny.    Back in college I once caught myself writing a 9 while pressing really hard on the paper where the 'shift' key would be.   Sadly my pencil didn't understand such notation and produced a 9, not a ( like I obviously wanted...

    <FONT face="Courier New" size=2>that's the most awesome thing i've heard all day.</FONT>

  • Mung Kee (cs) in reply to dubwai
    dubwai:
    Anonymous:
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    Oh come on, it is a perfectly cromulent word.

    That means?



    Simpson's reference
    http://en.wikipedia.org/wiki/Cromulent#Cromulent
  • dubwai (cs) in reply to Mung Kee
    Mung Kee:
    dubwai:
    Anonymous:
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    Oh come on, it is a perfectly cromulent word.

    That means?



    Simpson's reference
    http://en.wikipedia.org/wiki/Cromulent#Cromulent

    I meant what does 'improvisable' mean.

  • joodie (cs) in reply to dubwai
    dubwai:
    Mung Kee:
    dubwai:
    Anonymous:
    Mung Kee:
    dubwai:

    Anonymous:

    ...while their productivity in their workplaces is often measured in single digit scores, and the time that they waste in poring over the poor, wasted code could have been best spent on good, improvisable code.

    What's 'improvisable' code anyway?  I'm not even sure 'improvisable' is a word.



    I think it falls into one of these categories:
    http://www.dcc.unicamp.br/~oliva/fun/prog/resign-patterns


    Oh come on, it is a perfectly cromulent word.

    That means?



    Simpson's reference
    http://en.wikipedia.org/wiki/Cromulent#Cromulent

    I meant what does 'improvisable' mean.



    The article on "cromulent" should have explained.


  • Bill Kerney (unregistered) in reply to dubwai

    Believing that Equals with or without comparing case will have any sort of noticeable performance impact is just laughable. People care about performance at all the wrong times. :p

    This code is not a WTF. Perhaps it is reading keys from the keyboard, and at some point he might want to change a key binding from a '9' to a 'P'. If this was a possibility, he is 100% correct to use ignores case. Especially so, if changing the key bindings is a common operation, or if they might want to extend it into the future to perhaps read from a .cfg file. Otherwise they make a trivial change and the code breaks.

    There's nothing wrong with this code, especially if its within the context of a larger switch statement.

    -Bill Kerney

  • Anonymous (unregistered) in reply to David

    this 'guy'??
    dude! How the hell did you guess correctly!
    I am a guy!!!

Leave a comment on “Safety In Numbers”

Log In or post as a guest

Replying to comment #:

« Return to Article