Capital Offense: How to Handle Abbreviations in CamelCase

The CamelCase notation is one of the most popular word separation schemes. It used to be my favorite as well, but these days, I happen to prefer underscores, just like Kernighan and Ritchie did. But this is just my personal taste and it might be subject to change. I certainly don’t want to convince you to change your style. As always, it is more important to follow one style consistently than trying to find the “best” style.

Speaking of consistency, if there is one clear downside of CamelCase, it’s that it seduces people into being inconsistent — at least if abbreviations (or acronyms) are used. Take a look at some real-life examples from the Java API:

But what an inconsistent mess this is! Followers of the CamelCase school of thought obviously have difficulty deciding how to handle abbreviations. In some cases, an abbreviation is written all-uppercase, in other cases only the initial character is capitalized. To avoid such mixes, some coding conventions, like Python’s PEP-8, try to cure this by giving explicit advice:

When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError.

I totally disagree. While it works in simple cases, it leads to abominations when one abbreviation follows another:

The only convention that works reliably is this: “Treat abbreviations just like ordinary words”. That is, don’t use all-capital letters:

This works also if identifiers have to start with a small letter (e. g. names of local variables):

Comments (7)

  1. 23:13, 03-02-2015Matt  / Reply

    Great article … totally agree.

  2. 21:18, 14-07-2015Nathaniel Anderson  / Reply

    Nice article. A related stackoverflow link re: CamelCase, abbreviations, and acronyms. http://stackoverflow.com/q/15526107/1175496

  3. 16:50, 19-02-2016Artur  / Reply

    It really gets awkward when trying to use units:

    ConvertToMHz -> ConvertToMhz
    SensivityLimitdB -> SensivityLimitDb

    decibel turns into database.
    I wish I could find a acceptable solution for this, other than using underscores.

  4. 16:05, 08-03-2017frnk  / Reply

    @Artur: How about:
    ConvertToMegaHertz -> ConvertToMegahertz
    SensivityLimitDeciBel -> SensivityLimitDecibel
    ConnectToDataBase -> ConnectToDatabase
    Whatever is “Sensivity” anyway… but that’s what you got to know! ;-)

    @Ralf: Great thinking with good examples! “XMLIDREF” really is convincing.

  5. 20:51, 13-04-2017Jeremy Moritz  / Reply

    Glad to have this article with clear examples to demonstrate this. Thank you!

    I would add that “camelCase” with the first letter capitalized is commonly called “PascalCase”. I always use this distinction between the two (and capitalize them as you have in your examples).

  6. 08:21, 05-08-2017Jam Risser  / Reply

    Thanks, I’ve been trying to figure out what to do about this, and I think you’ve helped me decide.

  7. 13:32, 21-02-2018Hans  / Reply

    This is the reason I don’t use camel_case. It introduces inconsistencies, no matter how you use it.

Leave a Reply