- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Are they really reversing BOTH strings!?
I mean, it would make some sense if only one was reversed but this O_O.
Admin
I'd name the function "returnsTrueSometimesAndFalseOtherTimesYeahIDontReallyNowEither".
At least it'd be honest.
Admin
And why are they taking the substring from 0 to 11? they might as well call this method method0.
Admin
I'd go further and spell "Know" correctly
Admin
Good job the developer didn't spoil the fun by filling in the "description" in the comment block.
Admin
And it's an instance method that doesn't in any way seem to care about the instance it is being invoked on.
Admin
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.
Admin
public boolean last11CharsAreEqualButTheRestIsNot(String, String);
weird.
Admin
Oh, I see the WTF. He didn't reverse the bits in each character.
Admin
Fear the programmers who can use substring to create a WTF and still don't know how to get LAST 11 chars.
Admin
You call a code written in 2002 old? How old are you?
Admin
And they missed the most important JavaDoc element:
@author clueless_dolt
Admin
It's good they did what they did because.......
A.trim(); return A.endsWith(B.substring(B.length - 11));
Is sooooo confusing.
Admin
You think that's bad? You should see mightContainEqualButNotSameObjectSlantwise.
Admin
Admin
Awww... this was coded on Valentine's day. How sweet.
Admin
Admin
Well, that explains it. The programmer was probably busy doing.... other things. Alone.
Admin
In honor of the great valentines day massacre I'm sure.
Admin
there is a Bug: if string1==string2==strings1.reverse() "otto"?, then it returns false, when it should not.
Admin
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)...
Admin
Admin
"otto" would fail the substring.
Admin
WTFery:
1)reversing both substrings 2)what about palindromes?
Admin
Admin
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!
Admin
This could be the way it's meant to function.
Admin
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.
Admin
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();
Admin
containsNotEqualBackwards("abcdefghijklmnop ", "fghijklmnop") won't work either
compareFrom.substring(0,11).trim() should have been: compareFrom.trim().substring(0,11)
Admin
So...
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).
Admin
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.
Admin
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!"
Admin
Admin
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.
Admin
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.
Admin
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.
Admin
Admin
Admin
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 :)
Admin
you mean IE6?
Admin
That's because all programming languages are the work of the devil.
Admin
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?
Admin
Admin
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.
Admin
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 :)
Admin
Admin
That is beautiful...
Admin
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.
Admin