Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acronyms in Camel Back

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?

like image 406
Stroboskop Avatar asked Jul 24 '09 10:07

Stroboskop


People also ask

Should acronyms be capitalized in CamelCase?

When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton . However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io . Do not use abbreviations in identifiers or parameter names.

What is CamelCase example?

Meaning of camel case in English. the use of a capital letter to begin the second word in a compound name or phrase, when it is not separated from the first word by a space: Examples of camel case include "iPod" and "GaGa".

What is snake case vs camel case?

When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter. In contrast, snake case uses an underscore between words to create separation.

How does camel case work?

CamelCase Defined Camel Case (stylized as CamelCase), is a convention of writing phrases or compound words in such a way that they form a single word. The first letter of each of the words is capitalized so that each of the words that would make up the constructed term could be read easily.


Video Answer


2 Answers

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?

like image 144
AronVanAmmers Avatar answered Oct 06 '22 05:10

AronVanAmmers


Two reasons:

  1. It's easier to distinguish where one acronym ends and the other begins in identifiers where they're placed after each other, for instance in XmlHtmlConverter. Now XML and HTML aren't such good examples, because everyone knows what XML is, and what HTML is. But sometimes you'll see less obvious acronyms and then this becomes important.
  2. Eclipse is smart with words and their initials. For XmlHtmlConverter, you can type in XHC in the Open Type dialog and it will find it. For an XMLHTMLConverter, the initials would be XMLHTMLC which is of course a bit longer.
like image 44
jqno Avatar answered Oct 06 '22 03:10

jqno