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 (11)

  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.

  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.

  8. 18:29, 23-09-2019Peter  / Reply

    @Ralf, I share your outrage. “Abomination” really is the only word for it. Adding to the mix, what is going on with XmlIDREF? REF isn’t even an acronym, it’s an abbreviation. If not capital, surely at least arrestable.

  9. 13:13, 09-01-2020Adam Lesniak  / Reply

    There is one more problem with camelCase – that is lower letter owned names, like e.g. iPhone – it breaks concept of camel case and there is no simple way to handle this :(
    MyiPhoneConsole; //??? seriously

  10. 15:04, 09-01-2020Ralf  / Reply

    That’s right! My advice in the article is “Treat abbreviations just like ordinary words”, so let’s pretend the phone in question was called ‘intelligentPhone’. Then, you’d name the console ‘MyIntelligentPhoneConsole’. Thus, I’d go for ‘MyIPhoneConsole’.

  11. 08:09, 05-02-2021Mr Oldtown  / Reply

    I’m an underscore fan, being an Embedded guy; nevertheless, lately our industry was flooded with CS guys, adding OOP concepts in pure C and imposing this camel case nonsense :)
    Therefore, depending on the company, one must to adopt new “guidelines” (e.g. a simple “static” keyword you might find it redefined into something like “OUR_COMPANY_PRIVATE_TYPE”).
    Long live KISS :)

Leave a Reply