| « Prev | Page 1 | Page 2 | Next » |
|
Are they really reversing BOTH strings!?
I mean, it would make some sense if only one was reversed but this O_O. |
|
I'd name the function "returnsTrueSometimesAndFalseOtherTimesYeahIDontReallyNowEither".
At least it'd be honest. |
|
And why are they taking the substring from 0 to 11? they might as well call this method method0.
|
|
I'd go further and spell "Know" correctly
|
|
Good job the developer didn't spoil the fun by filling in the "description" in the comment block.
|
|
And it's an instance method that doesn't in any way seem to care about the instance it is being invoked on.
|
|
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. |
|
public boolean last11CharsAreEqualButTheRestIsNot(String, String);
weird. |
|
Oh, I see the WTF. He didn't reverse the bits in each character.
|
|
Fear the programmers who can use substring to create a WTF and still don't know how to get LAST 11 chars.
|
|
You call a code written in 2002 old? How old are you?
|
|
And they missed the most important JavaDoc element:
@author clueless_dolt |
|
It's good they did what they did because.......
A.trim(); return A.endsWith(B.substring(B.length - 11)); Is sooooo confusing. |
|
You think that's bad? You should see mightContainEqualButNotSameObjectSlantwise.
|
Ah, but you also need to make sure they aren't equal, too. |
|
Awww... this was coded on Valentine's day. How sweet.
|
Re: containsNotEqualBackwards
2007-09-24 09:49
•
by
foo
(unregistered)
|
It all makes sense when you realize that the class is called StringReversedNotEuqalStrategyStrategy. |
Re: containsNotEqualBackwards
2007-09-24 09:51
•
by
jesstech
(unregistered)
|
|
Well, that explains it. The programmer was probably busy doing.... other things. Alone.
|
In honor of the great valentines day massacre I'm sure. |
|
there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.
|
Re: containsNotEqualBackwards
2007-09-24 09:57
•
by
Rob G
(unregistered)
|
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)... |
How on Earth can you reasonably say what it's supposed to do? |
Re: containsNotEqualBackwards
2007-09-24 10:08
•
by
DivineGod
(unregistered)
|
|
"otto" would fail the substring.
|
|
WTFery:
1)reversing both substrings 2)what about palindromes? |
Re: containsNotEqualBackwards
2007-09-24 10:14
•
by
jimi
(unregistered)
|
The palindrome bugs always get ya. |
|
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!
|
|
This could be the way it's meant to function.
|
|
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. |
|
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(); |
|
containsNotEqualBackwards("abcdefghijklmnop ", "fghijklmnop") won't work either
compareFrom.substring(0,11).trim() should have been: compareFrom.trim().substring(0,11) |
|
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). |
Re: containsNotEqualBackwards
2007-09-24 10:36
•
by
SkittlesAreYum
(unregistered)
|
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. |
Re: containsNotEqualBackwards
2007-09-24 10:37
•
by
Blort
(unregistered)
|
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!" |
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. |
Re: containsNotEqualBackwards
2007-09-24 10:38
•
by
SkittlesAreYum
(unregistered)
|
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. |
|
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.
|
Re: containsNotEqualBackwards
2007-09-24 10:41
•
by
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.
|
I don't even want to think about the definition of slantwise ;) |
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? |
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 :) |
Re: containsNotEqualBackwards
2007-09-24 11:00
•
by
joh6nn
(unregistered)
|
you mean IE6? |
Re: containsNotEqualBackwards
2007-09-24 11:03
•
by
Mr Fred
(unregistered)
|
|
That's because all programming languages are the work of the devil.
|
Re: containsNotEqualBackwards
2007-09-24 11:04
•
by
Blort
(unregistered)
|
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.
Are you suggesting that Firefox (or any other modern web browser) doesn't contain any code written more than five years ago? |
Re: containsNotEqualBackwards
2007-09-24 11:11
•
by
Mr Fred
(unregistered)
|
|
Re: containsNotEqualBackwards
2007-09-24 11:14
•
by
Mr Fred
(unregistered)
|
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. |
|
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 :) |
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. |
Re: containsNotEqualBackwards
2007-09-24 11:45
•
by
Joon
(unregistered)
|
That is beautiful... |
|
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.
|
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. ;) |
| « Prev | Page 1 | Page 2 | Next » |