- 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
Admin
What would be awesome is if there were a program that could generate this Constants file for you... hmmm...
Well, no, it wouldn't, but the idea of a single constants file with business logic named "Constants.whateversuffixyouuse" is lame. The file that has the business logic should be named something no lamer than "BusinessConstants.whateversuffixyouuse". All those other things should go live in their own private .hell files.
P.S. Alex: that CAPTCHA thing just used black text on a background gradient fading from dark blue to black with a tinge of red.
Admin
Admin
Groaaaaaaaaaaaaaaaaaaaaaaaaaaaaan!
Admin
Honestly, has anyone ever worked on software where all the business rules were known? Everywhere I've ever been, there was never even verbal lore about business rules. Everything had to be inferred.
The other day I was working on a stored procedure that formed the heart of our product's data storage capability. I noticed dozens -- maybe hundreds -- of lines of SQL that seemed to churn the data around from one temp table to another in no useful way. Just for the fun of it, I went to our data access expert and asked him what all of this was supposed to accomplish.
"Beats the hell out of me," he answered. "Hey, I didn't write this. But don't take out anything -- there's no way to tell what you might break."
It's not really a WTF -- more like Business As Usual.
Admin
Admin
Are you pointing out the fact that constants should be, um CONSTANT, and variables, should be, um VARIABLE?
Admin
Admin
Admin
the REAL WTF is none of these are marked "final" they can all be changed at runtime! So much for "constants"!
Admin
If the first 6 months of your project are spent defining constants....
and your bosses are OK with this....
then I say "Go For It!".
Admin
Except, as misguided and insane as this code is, that isn't how _2 would be used. Instead, it would be something like this:
Stupid? Absolutely. But you would not instantiate _2.
Admin
The reply is "Nothing happens."
Admin
Wow this really reminds me the code I'm forced to maintain right now (It's a giant WTF). There's this lovely hierarchy of constants stuffed into interfaces, so EVERY class in the codebase implements the interfaces. It looks something like this:
XMLConstants: 300 constants CRMServerConstants: 100 constants CRMServerXMLConstants(CompanyName): 3000 constants
They also love to use constants to build sql queryies, so we get these lovely things like:
String sql = SELECT + STAR + FROM + DBSchema.TABLENAME.COLUMNNAME + WHERE + DBSchema.TABLENAME.COLUMNNAME + EQUALS + FLAG_NO
it's very readable...
Admin
Admin
The real WTF is all the totally incorrect code that some of you are throwing about:
WRONG! What if the value of 14 changes? It SHOULD be:
public static String _ONE = "1" public static String _FOUR = "4" public static String _FOURTEEN = _ONE + _FOUR
public static String _GREATER_THAN_OR_EQUAL + _FOURTEEN
Even this is only a interim solution. The real way to do it would be to define every PRIME number as a string, and then define every other number as the sum of those primes (casting them back to int, of course)
public static String _TWO = "2" public static String _THREE = "3" public static String _FIVE = (String)((int)_TWO + (int)FIVE)
And on the same heels, wtf are you doing putting this all in one string? What if some of those numbers change? What if someone doesn't have access to substring?
public static String _PI_COMPLETE_FIRST_DIGIT = _THREE public static String _PI_COMPLETE_DECIMAL = _DECIMAL public static String _PI_COMPLETE_FIRST_DECIMAL = _ONE public static String _PI_COMPLETE_SECOND_DECIMAL = _FOUR public static String _PI_COMPLETE_THIRD_DECIMAL = _ONE public static String _PI_COMPLETE_FOURTH_DECIMAL = _FIVE
And so forth. If you really NEED a single _PI_COMPLETE variable, we can accomidate you in the meantime:
public static Array _PI_COMPLETE _PI_COMPLETE[_ZERO] = _PI_COMPLETE_FIRST_DIGIT _PI_COMPLETE[_ONE] = _PI_COMPLETE_DECIMAL _PI_COMPLETE[_TWO] = _PI_COMPLETE_FIRST_DECIMAL _PI_COMPLETE[_THREE] = _PI_COMPLETE_SECOND_DECIMAL
And so forth. If you want NEGATIVE PI, well, that will be in a future revision. We can't perfectly rely on the runtime to provide us with truly accurate negative values for pi because of the extra bit. For now just take your value, convert it to a string, and append
_MATH_SYMBOLS_NEGATIVE_MINUS_SIGN
Admin
Personally I have figured out that many "constants" never are and are better off in a database table.
But excessive constantification of general rules and values is often outright stupid and doesn't improve on the code at all.
However sometimes I do use the following:
public final static String CURRENT_USER="CURRENT_USER";
and then use that when I for example do a session.getAttribute() in a Servlet. This allows me to look for all references to the constant instead of doing a search for the string and maybe end up with a bunch of false matches.
Admin
I worked for 2 months at a place where I had to maintain an awful system like the one in this story. The guy who created it had a 5k line class called "ConstantsAndGlobals.java". As soon as I saw that I knew that I was in trouble.
A constants class in Java really has no place. If you cannot figure out how to create an OO pattern that will allow you to place the necessary constants in the Interface/Abstract class then retire.
Admin
So beautiful... Can't... open eyes...
Admin
It looks to me like The Real WTF is that these constants are defining arithmetic operators and numbers as strings. The only way that even remotely makes sense is if this is some kind of code generator and those need to be printed frequently.
My guess is someone thought a Java String was equivalent to #define in C.
Admin
No they are equal but internally are stored differently, this is common with floating point numbers where the sign is stored as a bit.
(-0.0 == 0.0) results in: true
Admin
The decimal hardware allows negative zero, where COBOL often runs. Ones-complement binary also has the negative zero problem.
COBOL systems do run on x86 hardware, with software decimal arithmetic. See the IEEE-754 standard, which has a singel zero (as I recall).
Admin
It was on a System/390 that I first discovered this. Micro Focus COBOL on x86 hardware also demonstrated the problem. I think that it could probably happen on any system that implements packed-decimal numeric fields.
It's been a while since I used COBOL, so this is from memory. Define an 8-digit packed-decimal numeric field. Then redefine the storage as two four-digit packed decimal fields. Set the 8-digit field to a negative, with zeroes in the uppper four digits, then set the second of the four-digit fields to zero. The 8-digit field now has the value of -0.
Admin
You do realize that's a string, right? So it's not being used to compare anything to 14... It's probably included in the app's output.
If you really wanted to keep from typing the code (not the string) >=14 a lot, you should make a function.
Last but not least, WTF is up with putting a number in the constant name like that? The constant name should describe the MEANING of the constant, not its contents. Like, what is 14? The number of days in two weeks? One more than a baker's dozen? That code is not even close to good practice.
I pray to Allah that you are just kidding.
Admin
Your daily grind is over. You're no longer maintaining a huge application that your whole team hates. You're sitting alone in a peaceful meadow. There is a small mailbox here. Your computer is in front of you, and your favorite IDE is loaded up on the screen. You're starting a new project — a project in which you will guide the overall design. Your business rules are well-defined and you know them like the back of your hand.
Opening the mailbox reveals a leaflet.
This leaflet contains the most recent MFD update. Your eyes immediately melt, followed by the skin on your face. It's not like you were using those, anyway.
Your score is 0 (total of 350 points), in 2 moves. This gives you the rank of WTF.
Admin
Hey, at least that bug would only have to be fixed in one place ;)
Admin
As they say:
Variables don't.
Constants aren't.
:o)
Admin
True, but that is not what I said. The primitive double values -0.0 and 0.0 are equal. However, the equals method on the Double wrapper class treats Double objects created with those values as being different. For example, if you have:
Double neg = new Double(-0.0); Double pos = new Double(0.0);
Then neg.equals(pos) == false. Try it.
Admin
No, not in itself. Using an interface (or an abstract class) for constant definitions is much better than a concrete class (like in today's WTF), at least in the absence of enumerated types.
The problem with such interfaces are dumb people who implement these interfaces in classes where they intend to use the constants, only to save themselves typing the interface's name to qualify those constants, thus completely defeating the purpose of the interface concept.
This is the reason for the new and shiny (and also completely redundant) "static import" feature in Java 5+. Dumb developers are the reason for dumb language additions, most obviously ;o)
Admin
The twisted, masochistic part of my brain would love to see the whole file for some reason.
...I must be sick.
Admin
If that source code was in the mailbox, I would have offed myself with the Troll's axe.
Admin
Nice fantasy, but I would actually create some documentation for the design before writing that code file. This will help if another programmer joins the project later and/or becomes its maintainer.
Admin
WTF? Arkansas == AR.
Alaska == AK.
_AK = AB
Obviously Alberta has been annexed by Alaska. Hey wait, I can see Russia from my house...
-Lego.
Admin
Not without reason - if you'd have read the relevant API docs, you would not have been surprised by this ;o)
Snip from java.lang.Double#equals' API doc:
"(...) Note that in most cases, for two instances of class Double, d1 and d2, the value of d1.equals(d2) is true if and only if
d1.doubleValue() == d2.doubleValue()
also has the value true. However, there are two exceptions:
If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false.
If d1 represents +0.0 while d2 represents -0.0, or vice versa, the equal test has the value false, even though +0.0==-0.0 has the value true.
This definition allows hash tables to operate properly."
Admin
I used to come here for the articles... these days though I come here for topCod3r's awesome trolls.
(Seriously, google his replies)
Can I flag him as 'friend' somehow and insta-mod his posts to blue status a la slashdot?
Admin
Yet another product of the American education system.
Admin
Wait a minute! Sales tax is a constant? In what economic universe?
And who would store pi in a database? I mean, unless it was strawberry...
Admin
Really, that should be:
#define ONE_THIRD_OF_THE_MEANING_OF_LIFE 14
Admin
I don't even understand the point of the first exception, although I'm sure I would if I avoided the brown stuff.
The second exception is, however, bizarre. Does this mean that the standard Java hash table uses floating point values to represent keys? Or is there some even more mind-boggling reason for this completely counter-intuitive behaviour?
Implementing a sensible algorithm allows hash tables to operate properly.
Java.equals(_WTF);
Admin
Well, I wasn't actually surprised by it; I was responding (in a quote that seems to have gotten lost somewhere) to someone who claimed that COBOL was the only language that treated -0 and 0 differently.
And I agree (with someone else I can't be bothered to quote just now because I'm in a hurry) that Java can be trippy. Wrapper classes for primitive data types have long been a gold mine for WTFs.
Admin
its pitch black. you are likely to be eaten by a grue.
Admin
I think TopCod3r's awesome VB skills allow him to make OVER 9000 dollars a year!
Admin
This is an agile technique to streamline the look-up of constants. When I'm looking at code, what good is a variable named $number_of_otters_in_my_pants? It doesn't tell me how many otters are in my pants. I have to count them or go look up the value of this constant. Just put "7" in the code. If one of the otters leaves, all I have to do is a search and replace "7" to "6".
Admin
Taste mild, 09:19 in length. Best served warm with a generous helping of WTF.
Admin
I agree completely. However, I wouldn’t classify TopCod3r as trolling. TopCod3r’s clever, sarcastic comments truly add to the fun here. It’s even more fun when you don’t realize at first who posted it – and thus miss the tongue planted firmly in the cheek.
Admin
Oh ... and get somebody to explain the Use Case Scenarios for you who isn't doing five to ten for Animal Husbandry.
Admin
Admin
No, you're just the only one who thought it was obscure enough to merit a "am I the only one who caught it" post?
Not knowing that reference would be like not knowing where the term "Good Samaritan" comes from.
Admin
If a class is supposed to act like a primitive, then it should always act like that primitive. "We felt that making == a bitwise operation even though there's a perfectly workable builtin because we don't know better" is just sloppy.
Zero should frakking equal zero. To do otherwise is a bug. The only place I ever want to see "-0" used in all seriousness is in a limit term, e.g. lim as x -> -0 of 1/x = -inf.
Admin
Ima call bullshit on this one..