Skip to content

Instantly share code, notes, and snippets.

@adashrod
Last active February 17, 2026 20:27
Show Gist options
  • Select an option

  • Save adashrod/66564c690906c9b774e77ddacbd06e1b to your computer and use it in GitHub Desktop.

Select an option

Save adashrod/66564c690906c9b774e77ddacbd06e1b to your computer and use it in GitHub Desktop.
A rant about how to properly camel-case acronyms and abbreviations

Why using all-caps acronyms/abbreviations in camel case names is wrong

or, write MyUrlClass, not MyURLClass

Camel case

General Rules:

  • Each word is capitalized
  • no spaces
  • only alphanumeric characters

Upper Camel Case (aka Pascal case)

A scheme in which the first word is capitalized, e.g. ThisIsUpperCamelCase, e.g. what's conventionally used in Java class names.

Lower Camel Case (sometimes simply called camel case)

With an exception to the "each word is capitalized" rule, the difference is that the first word is not capitalized, e.g. thisIsLowerCamelCase, e.g. what's conventionally used in Java local variable names.

Sentence case to camel

Example sentence 1: Aaron is my name.

  • Why is the name Aaron capitalized?
    • a rule (not unique to English): proper nouns are capitalized, first word of the sentence or not

Example sentence 2: My name is Aaron.

  • Why is the word My capitalized?
    • another rule of (again, not only) English sentences: the first word of a sentence is always capitalized.
  • Why is the name Aaron capitalized?
    • see above^
  1. Convert sentence 1 to upper camel: AaronIsMyName
  2. Convert sentence 2 to upper camel: MyNameIsAaron
  3. Convert sentence 1 to lower camel: aaronIsMyName
  4. Convert sentence 2 to lower camel: myNameIsAaron

These conversions are unremarkable, but there is one thing to note: in conversion #3, aaron is not capitalized. Why? Because the rule for lower camel case is that the first word is not capitalized. Keeping the original capitalization (e.g. boolean AaronIsMyName = true) would be wrong in Java, so we ignore the original capitalization and follow the camel case rule. Camel case doesn't care about your proper nouns or sentence rules. In other words:

Camel case does not preserve or respect the original case of the input.

Title case to camel

Example title 1 (as in book/movie title): Big Action and the Exciting Adventure

  • Why are all words capitalized except and and the?
    • (some) rules of title case as used in names of books/movies/works of art/etc:
      • all words are capitalized
      • exceptions: conjunctions (and/or/...), prepositions (in/of/...), articles (the/a) are generally not capitalized
      • exceptions to this^ exception: the first and last word are always capitalized
  1. Convert title 1 to upper camel: BigActionAndTheExcitingAdventure
  2. Convert title 1 to lower camel: bigActionAndTheExcitingAdventure

Again, unremarkable. Why is the word big in conversion #6 lowercase? After all, in title case, the first word is always capitalized. However the output isn't title case; it's camel case, and so we follow the rule of lower camel case and the first word is not capitalized, regardless of how it is in the input. And why are the words And and The capitalized in both? Same reason- in both upper and lower camel case, the first letter of every word (after the first) is capitalized, regardless of the original. Camel case doesn't care about your titles. Again:

Camel case does not preserve or respect the original case of the input.

Fragments

Example fragment: PhD students

  1. Convert fragment to upper camel: PhdStudents
  2. Convert fragment to lower camel: phdStudents

For conversion #7, the input starts withPhD and the upper camel result starts with Phd, so it's not PhDStudents because according to the camel rules that each word has the first letter capitalized, that would mean the input tokens were Ph, D, and students. Why not make it PhDStudents? Well... for conversion #8, the lower camel result starts with phd. Arguably, if you wanted the upper camel output to be PhDStudents, then for consistency, you'd have to make the lower camel version phDStudents, which serves no useful purpose capitalizing only the 'D' in PhD. The conclusion: treat each token as a word, ignoring any capitalization rules of the input.

Camel case does not preserve or respect the original case of the input.

The main motivation of all of this

Some like to maintain all-caps acronyms when putting them in camel case.

Some examples from Java and DOM (All-caps scheme 1):

  • java.net.HttpURLConnection
  • javax.xml.ws.http.HTTPException
  • java.net.JarURLConnection
  • org.omg.PortableInterceptor.ORBIdHelper
  • javax.xml.bind.annotation.XmlIDREF
  • XMLHttpRequest
  • HTMLHRElement

I listed these examples because they clearly point out one of the problems with this approach; if you have two or more adjacent acronyms, the all-caps-maintaining pattern falls apart. One option is to maintain all-caps for one acronym and camel-case the other, as in HttpURLConnection above. URL maintains all caps, but HTTP is treated as a word.

In scheme 1 examples, some maintain all-caps for the first acronym in a series, some the second. There's no consistency to this attempted rule.

There's similarly no consistency about maintaining all-caps for specific "special" acronyms. Sometimes HTTP is all-caps above, sometimes not. The choice of which to maintain is arbitrary.

Another method is to maintain all-caps in all acronyms (All-caps scheme 2):

  • java.sql.SQLXML
  • javax.xml.crypto.dom.DOMURIReference
  • javax.management.remote.rmi.RMIIIOPServerImpl
  • JSONAPISerializer

The supposed benefit behind maintaining all-caps is that context of an acronym being an acronym is not lost; you know that a string of all-caps chars is an acronym. Even this fails when a name has multiple acronyms in either of these two schemes. In scheme 1, context of an acronym being an acronym is lost because the rule of maintaining all caps is not always followed (e.g. you can't discern that Jar was the acronym JAR by looking at JarURLConnection). In scheme 2, context of an acronym being an acronym is not lost, but context of where acronyms start and stop is lost, as all adjacent acronyms become mashed together.

Another big downside of maintaining all-caps: It requires human context to parse. With scheme 1, human knowledge of what is or isn't an acronym is needed to know whether a camel case token is a regular word or an acronym that is an exception to the scheme. With scheme 2, human knowledge of specific acronyms is needed to know where to split contiguous acronyms.

With either of the above 2 schemes, there's another problem. Imagine two Java classes ShortURL and URLAttributes, here we create variables with the same names as the classes.

ShortURL shortURL;

Above, standard Java naming convention, using all-caps acronyms, not a huge problem. But what if the class starts with an acronym:

URLAttributes urlAttributes;
URLAttributes uRLAttributes;

You can't maintain the all-caps acronym when using lower camel case. They're incompatible. The second option, uRLAttributes tries, but is misleading because now it looks like RL is the acronym.

The preferable solution is to treat acronyms and abbreviations as words, only capitalizing their first letters. The downside of this: you lose context by camel-casing all-caps acronyms, however that's not important. You lose context of all capitalization of all words when using camel case, whether acronyms, abbreviations, proper nouns or anything else. Camel case is inherently destructive to the input case, so there's no point in trying to maintain it.

Camel case does not preserve or respect the original case of the input.

// end of rant

See also:

@carlfriedrich
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment