I often see Java class names like
XmlReader
instead of
XMLReader
My gut feeling is to completely upper case acronyms, but apparently many people think differently. Or maybe it's just because a lot of code generators are having trouble with acronyms...
So i would like to hear the the public opinion.
How do you capitalize your class names containing acronyms?
We use the camel case convention like Java and .NET do. Not for reasons of code generators, but for readability. Consider the case of combining two acronyms in one name, for example a class that converts XML into HTML.
XMLHTMLConverter
or
XmlHtmlConverter
Which one do you prefer?
I find that XMLReader is more difficult to read. The reason is that you can't easily tell where the words are separated. I believe that acronyms with lower case should be accepted. You may be able to use upper case for class definitions, but what about instance variables:
XmlReader xmlReader;
Here you have to use lower case anyhow.
For acronyms I use the following rule :
If the acronym is of length 2, put the acronym in upper case.
For Ex : UIRule
If the acronym is of more length, I use the pascal casing for the acronym
For Ex : SmsValidation, XmlReader
Pascal Case is used in the .NET framework. So
XmlReader
is preferred in Microsoft environments.
I have to agree with AronVanAmmers that this is easier to read that the alternative.
Reference: Microsoft Design Guidelines for Class Library Developers
I believe that, in general, class names should be written as you expect them to be read. For example, when speaking the class name aloud I would say "X-M-L reader", so I would name the class "XMLReader". However, I would name a hypothetical "REST service" class "RestService", since, in general, "REST" is not pronounced "R-E-S-T" but "rest". For something like "SQL", I could go either way, since some people say "S-Q-L" and others say "sequel". But it really just comes down to personal preference.