- 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
private static final byte [] FRIST = { (byte)'f', (byte)'r', (byte)'i', (byte)'s', (byte)'t' };
Admin
How can you not code for a tri-state boolean in this day & age?
Admin
Yeah, initializing the static constants as "true".getBytes("US-ASCII") and "false".getBytes("US-ASCII") might have been somewhat clearer. But does it rise to the level of a WTF?
Whether having a function that does what this one does is reasonable in a larger context, and whether the microoptimization of returning static arrays rather than allocating a new one for each call is worth the slight loss of readability, that's a different matter -- but one that is impossible to judge without knowing something about what the function was used for.
Admin
Impossible to judge? How about the fact that he's spelled "false" wrong? The fact that he's done this in such a way that it's POSSIBLE for false to not be false kind of shows that it really is a WTF.
Admin
Sorry, you're working off a completely fasle premise here
Admin
Think of the possibilities!
Admin
You for got to un-Nagesh before posting a serious comment...
Admin
Well we can fix that.
Admin
But still, a spelling error in the implementation does not tell anything about whether or not there's a good reason to want a method that produces a human-readable ascii representation of the value as bytes, or whether it is called so often that sharing the return values is worth the trouble.
Admin
fasle?
Admin
No he didn't
Admin
That's a little generous. I'm thinking they're a D- programmer, at best.
Admin
As usual with Remy articles, it gets even more absurd if you view source:
(byte)'t', (byte)'r', (byte)'u', (byte)'e'
All that to say "true"? WTF!
Admin
I'll see your tri-state boolean and raise you another two: MsoTriState Enumeration
Akismet may be right occasionally.
Admin
-1 is not a byte array! >:(
Admin
Admin
Since you're all complaining about spelling errors in the implementation, I'll just leave you with HELO. Oh, and don't go anywhere NEAR the old DirectConnect protocol...
Admin
Discrimination against negative numbers in this day and age! Go burn in the middle ages you fool.
Admin
The real WTF is the missing constant for FILE_NOT_FOUND.
Admin
Sir, your comments are "fasle"
Admin
Had you read the article a little closer, you would have known that it should go more like this-
private static final byte [] FRIST = { (byte)'f', (byte)'i', (byte)'r', (byte)'s', (byte)'t' };
Admin
I think this can be filed safely under "job security"...if it wasn't done in the name of job security then I'd very very very afraid because there is the chance that the person who wrote that doesn't work there anymore....
Admin
Thats just awesome.
Admin
I honestly don't think a C developer would do something like that. Wow.
Admin
Not one person here has asked the obvious question (well, obvious to me, anyway):
Why the blue blazes do they return byte arrays rather than character arrays or even just plain old strings?
Admin
Poor baby wanted to simulate a C string.
Admin
Ow! I think I just had a mini-stroke reading that code.
Admin
It's inelegant source, but it has certain advantages over a JavaScript source highlighter (like working in RSS readers). It's still an automated tool- you couldn't pay me to write code like that.
Admin
Poor baby didn't NULL-terminate his simulated C string.
Must be an optimization. This way the output is up to 20% smaller!
Admin
I never thought I would put these words together in a sentence, but Nagesh is right. Without knowing how or where this function is used, how can we say whether it's a good function to have or not?
Yes, it would have been a lot easier to read if he had used getBytes. I'm guessing the writer wasn't familiar with that function. But that's a pretty minor issue.
The bigger question is, what does he use these byte arrays for? If he passes booleans between functions as byte arrays and tests them by comparing the bytes, that's stupid. But if, say, he does this because he's passing booleans to another system and that system's API requires a byte array, what else is he supposed to do?
Admin
TRWTF is Java in that an idiomatic implementation isn't even much shorter than the implementation in the article due to checked exceptions.
Admin
Admin
(Actually, we have a grammatically-correct Nagesh here, and I think that's who you replied to.)
Admin
Admin
Ah the MS Frontpage! It burns!
Admin
Admin
Or the HTTP header Referer.
Admin
At least he/she didn't simulate a g-string
(Sorry couldn't resist)
Yours Yazeran
Plan: To go to Mars one day with a hammer
Admin
Come on! You just made ['t','r','u','e'] into ['t','r','e','u']!! What kind of fix is that?
Admin
HELO makes sense: All the SMTP commands were deliberately made to be 4 characters. Other examples are RCPT, VRFY, and EXPN.
"Referer" was just a spelling error.
Admin
Well, it's really only a manifestation of the quantum state of FALSE. There's a finite probability that FALSE can escape its quantum well and 'jump' to a new, LESS_FALSE state.
Admin
The best part: They misspelled 'FALSE'
Admin
Admin
Hey did anyone notice they spelled "false" wrong yet?
Admin
Admin
TRWTF is a Remy article without a hidden cornify link.
Admin
or, in c++
bool flag = true; cout << boolalpha << flag << endl;
If you really wanted a string, then use stringstream.
Admin
So the guy implemented a ToString on booleans.
now, Of course it's not the most graceful way in the world to do it, but it's not WTF degrees of ungraceful
Admin
I made it shorter just for you :)
Admin
That may be the reason it's implemented. Some service provider sends bytes over a socket, misspelled "false", and now this Tomcat service has to read it.
Not all WTFs are local!