File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes constant - naming conventions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "constant - naming conventions" Watch "constant - naming conventions" New topic

constant - naming conventions

pete reisinger
Ranch Hand

Joined: Dec 30, 2009
Posts: 46
java naming conventions say that constants should be in upper case.
In our company I saw declaration of log4j:

So I was wondering why it's not 'LOG'. After some search there were two groups of people, one that uses 'LOG' and the other one that uese 'log'.
The argument for using 'log' was that the logger is not immutable, therefore is not a constant.
So ... should it be log or LOG?
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

Its just a convention, you can pick what you like. That said, I don't consider the logger to be a constant. For me, a constant is a numeric or String "magic value". Something like

final int MAX_SIZE = 10;
final String ERR_MESSAGE = "Programmer is a bozo";

your log example is just a static variable, its not a magic value.

Also, I do not use the name "log" for all of my loggers, it can be confusing when you subclass the file a few levels deep. So if my class is BigCoolThing,
i tend to name the static log variable bctLog
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
Personally I prefer "log" there. But the basic problem is that it's ambiguous - the naming convention is for "constants", but it's never really defined exactly what that means. Does it refer only to compile-time constants (which are well-defined)? Maybe. Maybe not. Enums? Final references to immutable types? Final references to mutable types? There really is no standard. Almost everyone who follows this convention will use it for compile-time constants and enums at least, but for anything else, it's a matter of opinion with no well-defined answer.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 607

just to add I always think its a good idea to pick and follow a naming convention within a group. It might not always be 'right' but as long as everyone in the group follows it its all good! Mixing up naming convention within a group even if its for the sake of correcting a wrong convention isn't generally a good idea!

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
I agree. Here's the link:
subject: constant - naming conventions
It's not a secret anymore!