• (cs)

    Are they really reversing BOTH strings!?

    I mean, it would make some sense if only one was reversed but this O_O.

  • Sven (unregistered)

    I'd name the function "returnsTrueSometimesAndFalseOtherTimesYeahIDontReallyNowEither".

    At least it'd be honest.

  • flux (unregistered)

    And why are they taking the substring from 0 to 11? they might as well call this method method0.

  • Mith (unregistered)

    I'd go further and spell "Know" correctly

  • awt (unregistered)

    Good job the developer didn't spoil the fun by filling in the "description" in the comment block.

  • anon (unregistered)

    And it's an instance method that doesn't in any way seem to care about the instance it is being invoked on.

  • Code monkey (unregistered)

    I guess the programmer was supposed to check if the last 11 chars of a string match something else. So he reversed both strings and then took the now-first 0-11 range.

    Probably because he couldn't think of a different way of getting the last 11 chars from a string.

  • MrTweek (unregistered)

    public boolean last11CharsAreEqualButTheRestIsNot(String, String);

    weird.

  • Dave (unregistered)

    Oh, I see the WTF. He didn't reverse the bits in each character.

  • (cs)

    Fear the programmers who can use substring to create a WTF and still don't know how to get LAST 11 chars.

  • Vic (unregistered)

    You call a code written in 2002 old? How old are you?

  • (cs)

    And they missed the most important JavaDoc element:

    @author clueless_dolt

  • Erik N (unregistered)

    It's good they did what they did because.......

    A.trim(); return A.endsWith(B.substring(B.length - 11));

    Is sooooo confusing.

  • (cs)

    You think that's bad? You should see mightContainEqualButNotSameObjectSlantwise.

  • (cs) in reply to Erik N
    Erik N:
    It's good they did what they did because.......

    A.trim(); return A.endsWith(B.substring(B.length - 11));

    Is sooooo confusing.

    Ah, but you also need to make sure they aren't equal, too.

  • (cs)

    Awww... this was coded on Valentine's day. How sweet.

  • foo (unregistered) in reply to anon
    And it's an instance method that doesn't in any way seem to care about the instance it is being invoked on.
    It all makes sense when you realize that the class is called StringReversedNotEuqalStrategyStrategy.
  • jesstech (unregistered) in reply to Licky Lindsay

    Well, that explains it. The programmer was probably busy doing.... other things. Alone.

  • (cs) in reply to Licky Lindsay
    Licky Lindsay:
    Awww... this was coded on Valentine's day. How sweet.

    In honor of the great valentines day massacre I'm sure.

  • allo (unregistered)

    there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.

  • Rob G (unregistered) in reply to allo
    allo:
    there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.

    So, someone knows what the code is for.. we may have our culprit ;)

    (Captcha - doom, takes you back to the glory days of PC gaming)...

  • (cs) in reply to allo
    allo:
    there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.
    How on Earth can you reasonably say what it's supposed to do?
  • DivineGod (unregistered) in reply to allo

    "otto" would fail the substring.

  • (cs)

    WTFery:

    1)reversing both substrings 2)what about palindromes?

  • jimi (unregistered) in reply to allo
    allo:
    there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.
    The palindrome bugs always get ya.
  • (cs)

    Dumb question...shouldn't there be a test to make sure there actually are at least 11 characters first? It may be antiquated thinking (but hey, I'm 45 and I know COBOL...I'm an antique), but testing the first 11 characters of a 10 character string smells like buffer over-runs to me!

  • (cs) in reply to jimi

    This could be the way it's meant to function.

  • (cs) in reply to n9ds

    It's java, the programmer doesn't have to care about buffer over-runs anymore :'( Or it just throws an exception, which crashes teh program \o/ unless it's caught, but looking at the code it's probably not.

  • (cs)

    if(s1.equals(s2)) return false; else if(s1.length() >= 11) return s1.substring(s1.length() - 11).trim().equals(s2.trim()); else throw new CompareFromStringShorterThanElevenCharactersException();

  • M&M (unregistered)

    containsNotEqualBackwards("abcdefghijklmnop ", "fghijklmnop") won't work either

    compareFrom.substring(0,11).trim() should have been: compareFrom.trim().substring(0,11)

  • (cs)

    So...

    • Returns false if the strings match exactly (including whitespace)
    • Returns true if the second string matches the last 11 characters of the first string (ignoring leading/trailing whitespace)
    • Returns false otherwise.
    • Throws IndexOutOfBoundsException if the strings don't match exactly and the first string is less than 11 characters long.

    I think that covers it.

    Christ knows what it was actually intended to do though (actually, maybe he doesn't, I don't remember the part of the bible where he learned how to program in Java).

  • SkittlesAreYum (unregistered) in reply to Gir
    Gir:
    It's java, the programmer doesn't have to care about buffer over-runs anymore :'( Or it just throws an exception, which crashes teh program \o/ unless it's caught, but looking at the code it's probably not.

    Java won't throw an exception. If the end index is beyond the length of the string, it will just return up to the end of the string. Same with Perl's substring(), IIRC.

  • Blort (unregistered) in reply to Vic
    Vic:
    You call a code written in 2002 old? How old are you?

    It should be impossible to call any Java "old". Some C might be old. A fair amount of FORTRAN is old. Almost all COBOL is old. Java isn't even middle-aged!

    Perhaps calling 5 year-old code "old" some sort of insight into the mind of the Java developer? "Ohh, that's more than 12 months old and doesn't use the latest java.util.flibFlobStringParserWoble class, I'd better re-write it!"

  • (cs) in reply to n9ds
    n9ds:
    Dumb question...shouldn't there be a test to make sure there actually *are* at least 11 characters first? It may be antiquated thinking (but hey, I'm 45 and I know COBOL...I'm an antique), but testing the first 11 characters of a 10 character string smells like buffer over-runs to me!
    To elaborate Gir's answer Nope, no buffer overruns in Java, since array boundaries are automatically checked on access. It will just throw an ArrayIndeyOutOfBoundsException or some such thing. Which is probably swallowed silently somwhere, judging from the code we see.
  • SkittlesAreYum (unregistered) in reply to SkittlesAreYum
    SkittlesAreYum:
    Gir:
    It's java, the programmer doesn't have to care about buffer over-runs anymore :'( Or it just throws an exception, which crashes teh program \o/ unless it's caught, but looking at the code it's probably not.

    Java won't throw an exception. If the end index is beyond the length of the string, it will just return up to the end of the string. Same with Perl's substring(), IIRC.

    Okay I'm going to go ahead and take this back. I read the Java documentation again and I missed the

    Throws: IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

  • (cs) in reply to death

    Does using monstrosities of parameter names like 'theStringToCompareFrom' actually lend any readability to the code? It seems like it detracts from it more than anything. Something short like fromString and toString (oh dammit, I guess that wouldn't work either), or whatever, would probably suffice.

  • Valdis Kletnieks (unregistered)

    I'm surprised not a single person has noted that in multinational companies, there might just be a need to process BIDI (BidDirectional) langauges, or ones that are read right-to-left, so comparing the last 11 characters might actually be The Right Thing To Do.

  • (cs) in reply to bstorer
    bstorer:
    You think that's bad? You should see mightContainEqualButNotSameObjectSlantwise.
    I don't even want to think about the definition of slantwise ;)
  • (cs) in reply to Blort
    Blort:
    Vic:
    You call a code written in 2002 old? How old are you?

    It should be impossible to call any Java "old". Some C might be old. A fair amount of FORTRAN is old. Almost all COBOL is old. Java isn't even middle-aged!

    Perhaps calling 5 year-old code "old" some sort of insight into the mind of the Java developer? "Ohh, that's more than 12 months old and doesn't use the latest java.util.flibFlobStringParserWoble class, I'd better re-write it!"

    Consider that that whole field of web development is only around 12 years old, and how much Java grew and changed in its first few years. Also, would you use a web browser that was five years old?

  • (cs) in reply to awt
    awt:
    Good job the developer didn't spoil the fun by filling in the "description" in the comment block.

    Or giving any piece of information that is not at the function declaration...

    He gets bonus points for using a @return tag with the type of the return value. Oh, yes, and follows all those design by contracts gidelines...

    Most usefull javadoc I eve saw :)

  • joh6nn (unregistered) in reply to punissuer
    punissuer:
    Consider that that whole field of web development is only around 12 years old, and how much Java grew and changed in its first few years. Also, would you use a web browser that was five years old?

    you mean IE6?

  • Mr Fred (unregistered) in reply to Phlip

    That's because all programming languages are the work of the devil.

  • Blort (unregistered) in reply to punissuer
    punissuer:
    Blort:
    Perhaps calling 5 year-old code "old" some sort of insight into the mind of the Java developer? "Ohh, that's more than 12 months old and doesn't use the latest java.util.flibFlobStringParserWoble class, I'd better re-write it!"

    Consider that that whole field of web development is only around 12 years old, and how much Java grew and changed in its first few years.

    True, but that just means that peoples perceptions are skewed. Just because your language is only a baby it doesn't make five year old code "old". It also doesn't mean it is automatically a good idea to continually re-write functioning code simply because the Sun Marketing Department thought up a new buzzword.

    Also, would you use a web browser that was five years old?

    Are you suggesting that Firefox (or any other modern web browser) doesn't contain any code written more than five years ago?

  • Mr Fred (unregistered) in reply to Valdis Kletnieks
    Valdis Kletnieks:
    I'm surprised not a single person has noted that in multinational companies, there *might* just be a need to process BIDI (BidDirectional) langauges, or ones that are read right-to-left, so comparing the *last* 11 characters might actually be The Right Thing To Do.
  • Mr Fred (unregistered) in reply to Valdis Kletnieks
    Valdis Kletnieks:
    I'm surprised not a single person has noted that in multinational companies, there *might* just be a need to process BIDI (BidDirectional) langauges, or ones that are read right-to-left, so comparing the *last* 11 characters might actually be The Right Thing To Do.

    That is because the right to left vs left to right is merely the spatial display convention indicating which characters are first vs last. It has nothing to do with the ordinality of the string elements which is present in the string array.

  • (cs)

    For me, the real WTF is just another case of people naming functions by how they are implemented rather than what they are for. The last 11 characters may be some domain specific information that may be guaranteed to be present by the time this function is called. For example if it were renamed to orderSpecialFeatureEqual() or whatever the real use was it would be less of a WTF.

    OTOH reversing both the strings is just mental :)

  • (cs) in reply to Phlip
    Phlip:
    Christ knows what it was actually intended to do though (actually, maybe he doesn't, I don't remember the part of the bible where he learned how to program in Java).
    This happened in that undocumented period between age 12 and age 30, and was done mainly so that he could program the CNC machines in Joseph's furniture factory.
  • Joon (unregistered) in reply to FredSaw
    FredSaw:
    This happened in that undocumented period between age 12 and age 30, and was done mainly so that he could program the CNC machines in Joseph's furniture factory.

    That is beautiful...

  • Loren Pechtel (unregistered)

    I also at first thought of backwards languages & UTF characters but that's not what's going on here. It's simply an attempt to see if the last 11 characters of the first string match the whole second string.

  • (cs) in reply to Blort
    Blort:
    Are you suggesting that Firefox (or any other modern web browser) doesn't contain any code written more than five years ago?
    No, my point is just that the computing field moves very quickly, and anything dealing with the web seems to move more quickly still. Five-year-old code might still be in use, but I would definitely consider it old--sometimes that's a good thing. ;)

Leave a comment on “containsNotEqualBackwards”

Log In or post as a guest

Replying to comment #:

« Return to Article