- 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
public static final int INTEGER_FRIST = 1;
Admin
Good to see that INTEGER_ONE and INTEGER_FIVE are defined twice. (Just in case)
Admin
COMMENT_FRIST = 1;
Admin
Yeah, but why don't they do
Those comparator values are bogus, which is an example why it's ok to use integers sometimes.
Admin
Auch, that hurts!
I use magic numbers all the time, I just make sure there's a comment line next to it explaining them. e.g. malloc(17) // 4*4(int) + 1 (\0)
Admin
Now, if 1 turned up to be 9, I don't mind, I don't mind. If all the hippies cut off their hair, I don't care, I don't care. Dig, 'cause I got my own world to live through And I ain't gonna copy you.
Admin
ONE == INTEGER_VALUE_ONE == PLUS_ONE == COMPARE_RESULT_ONE
This is a perfect example of my new favorite design pattern: Cargo Cult.
Admin
public static final float FLOAT_NOT_QUITE_PI = (LONG_VALUE_TEN + LENGTH_TWELVE) / (NINE_STRING + (COMPARE_RESULT_NEGATIVE * (PLUS_ONE + BIGDECIMAL_ONE) ));
mmmmmm... FLOAT_NOT_QUITE_PI..
Admin
TRWTF: public static final String ONE_STRING = "9";
Admin
If that;s Java it won't compile because of the repeated INTEGER_FIVE etc.
Admin
public static final String ONE_STRING = "9";
lolz
Admin
This is for future compatibility. If Java will ever drop primitive types, this guy is prepared.
Admin
Or maybe that's the beauty of the Constants class. If you want 5 to universally be 6, all you have to do is change a value in Constants!
Admin
Copy fail.
Admin
TRWTF is that this isn't in an XML file.
Admin
On the contrary, that shows the real flexibility of using constants. He was able to change ONE_STRING from "1" to "9" without having to dig through countless lines of source code.
Admin
It seems likely these are being used somewhere in conjunction with a Comparable or Comparator. If that's the case there's another WTF here in assuming that compareTo() methods will return -1 for "less than" and +1 for "greater than". The only assumption you're allowed to make is that it returns a negative value for "less than" and a positive value for "greater than".
Admin
Ahh, I see the WTF - what if they want a short or a float? Clearly this developer didn't go far enough with their implementation. Kudos for having constants specifically defined for comparison though - you just never know when they'll redefine the return values on comparator methods. Last time I updated my distribution I found that 17 was greater-than, 43 was less-than and -4 was equality. If only I'd had the foresight to use constant values instead of inline integers.
Admin
TRWTF is that Java has no way to change constant values dynamically.
Admin
UPPERCASE_T_STRING + LOWERCASE_H_STRING + LOWERCASE_A_STRING + LOWERCASE_T_STRING + ONE_SPACE_STRING + LOWERCASE_I_STRING + LOWERCASE_S_STRING + ONE_SPACE_STRING + LOWERCASE_B_STRING + LOWERCASE_R_STRING + LOWERCASE_I_STRING + LOWERCASE_L_STRING + LOWERCASE_L_STRING + LOWERCASE_A_STRING + LOWERCASE_N_STRING + LOWERCASE_T_STRING + EXCLAMATION_MARK_STRING
Admin
malloc( 4*sizeof(int)+1 ); // one int per season of year, 1 byte for trailer
Now the comment explains what the magic number means.
Admin
Admin
I think the last line was the funniest :
public static final String ONE_STRING = "9";
Admin
Don't u guys ever sleep? Perhaps a new joke next time at least? Is it too much to ask?
Admin
Why don't u write malloc(4 * sizeof(int) + 1) instead?
Admin
public static final Long LONG_VALUE_TEN = Long.valueOf(10); public static final Long LONG_VALUE_ZEARO = Long.valueOf(0);
Guy apparently needs a spell check as well as a programming lesson
Admin
Note to spoil your joke or anything... but Java already has a double not quite pi constant: java.lang.Math.PI
On another track, Java already has java.math.BigDecimal.ZERO and java.math.BigDecimal.ONE as well.
Admin
system.out.println(Constants.INTEGER_ZEARO + "th");
Admin
The Long and BigDecimal versions may make sense, if the java implementation is stupid enough to assume a constant number is an int and does a cast every time you assign a constant to a Long or BigDecimal.
Admin
ALPHALET_L ALPHALET_O ALPHALET_L
(I'm not spam!)
Admin
TRWTF is that this isn't in an XML file
Well, maybe. If 1 really equals 9 when XML is used, that might explain some problems I've been encountering.
Admin
I see the problem.
should have been
That's it, right?
Fixed.
Admin
Apprently it is.
Admin
Sigh. Sense of humour fail.
Admin
Way, way back in the yearo ZEARO...
Admin
isFileNotFound(TRWTF_ZEARO) = 1;
Admin
Assertion fail!
Admin
Admin
TRWTF is that this is actually an attempt to make Java Text-To-Speach friendly.
Admin
There are times when people mock me for not being able to code in C, C++, or Java - I'm a PHP developer (NO, stop screaming, that which I write is non WTF worthy - I fix WTF level code more often than not, have a severe hatred of anyone who's looked at "PHP for dummies" and thought "Hey, I've heard of PHP").... I can understand C++, Java, have written in Assembler, RPG, and Cobol in the past (RPG Cobol itself is a WTF), yet I code in PHP for the fun of it.
But this... This is evil. This code is wrong.
This is beyond "magic numbers", and is just laughable. But better yet:
I want to see the code when they have to change INTEGER_FOUR to have a value of 5 due to some management decision... I want to see STRING_FOUR have a value of "12".
Think of it. And then laugh nervously with me.
Admin
I have been quietly reading, enjoying, and sharing the wft for years. Today I am oddly compelled to comment. This one is literally melting my brain.
OMFGWTF
Admin
This kind of code often comes from having the "magic constant" rule enabled in PMD, and a "zero PMD warning" policy. This proves, if anything, that blindly applied rules are almost always stupid.
TRWTF is, what do you do if Oracle suddenly decides to change Java keywords? That's where C got it right with preprocessor directives:
(captcha: "odio" -> "hatred" in spanish)
Admin
Admin
LMAO That had me spraying coffee over my keyboard. Should be a featured comment.
If only more languages had the ability to change constants on the fly. It's the way of the future.
Admin
"That is brillant!" ??? Error: Won't compile!
Admin
public static final int FOUR = 4; public static final int INTEGER_FOUR = 4;
ah now it makes sense
Admin
Oh wake up. You just check the return value as greater-than-or-equal to the ONE value and less-than-or-equal-to the "NEGATIVE" value. Cor I dunno, do I have to do ALL your design for you.
Admin
I sincerely hope your use of "literally" is literally incorrect.
Admin
I hope you're trying to be ironic...
Admin
What is so bad about magic numbers? There are definitely some areas, namely all numbers that are used in more than one place. But I have seen more code where the developer did too much, than I have seen code where magic numbers were a bad thing. Some examples? Replace boolean-parameters with named constants like: DO_THIS = true; DONT_DO_THIS = false; The method-call read: foo(DO_THIS) and foo(DONT_DO_THIS) This does not help reading! Or the guy converting all assertion-messages to string-constants! Did not help the reading either.
Magic numbers are way overrated (I guess because it is so easy to check if someone uses them). You should use your brain instead of converting everything into a constant.