In the Style Guide is the following: "3.3 - All Other Identifiers All other identifiers, including (but not limited to) attributes, variables, methods and parameters will use this default naming convention. This includes final identifiers (using all upper case, as traditionally done in C, is a violation of OO abstraction)...." I don't understand why using upper case for final (constant) identifiers is a violation of OO abstraction. Isn't it a naming convention? That is, wouldn't I be violating a naming convention if upper case was not allowed? Is this covered in Just Java? I don't have the book yet, it's on its way.
"using all upper case, as traditionally done in C, is a violation of OO abstraction"
By using upper case for final identifiers, you are assuming that that particular variable will be a constant forever. Now, while that is probably true for pi (3.14...), most of the time you cannot guarantee that what is declared as final in your program will always remain a constant. By using the default naming convention, your program will be more flexible. Who wants to change hundreds of identifier names in an application just because the constant is now variable?
By keeping the identifiers the same, you are abstracting the thing it contains. There are plenty of times where we shouldn't care what the reference is referring to - an int or an Integer, an array or an ArrayList, a constant or a variable.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Mar 01, 2001
Marilyn, I had to read your reply a few times before it sunk in. I understand now. I've actually been faced with this problem in the real world a couple of times. But, a different naming convention for constants (use "Literal" in name, make all upper case, etc.) has been the only standard I've ever been taught or told to use. Using the same naming convention for constants as variables makes sense when taking into account that future life of the code. Thanks, richard
So, if the constant is constant, like PI, Gravity on earth, the speed of light in a vacuum, then its OK to capitalize it, but if the constant is line length, page length, or number of connections allowed, then its not really a constant, so it should not be in all caps. I can deal with something like that. I'm still trying to get myself out of Hungarian notation and inital caps for functions. I'm rather pleasantly surprised with the style guide. I've developed my own style over these many years of coding, and the only real eye-opener was spaces around identifiers, but it makes sense when you need to search for a variable.