Stop Capitalizing Acronyms in Your Class Names
LEGIBILITYMATTERSMORETHANGRAMMAR… or, rather, LegibilityMattersMoreThanGrammar
I like to be productive and efficient. So anything that unnecessarily wastes even a few moments of my time… well, it really bugs me.
That is why I am particularly bugged by a particular practice (nay, an anti-practice) that I see too often. FYI, AFAIK most folks would agree with me, so IDK why this anti-practice is so pervasive.
I’m talking about CamelCased class names with FULLY-CAPITALIZED acronyms.
You see these fairly often in Java.
ISBNValidator. Mercifully, the good folks who designed the java.net package decided to use
Http rather than
HTTP in class names, so we’re not cursed with the likes of
HTTPURLConnection. Not so with Apple, however, as anyone who’s worked with Objective-C, or even Swift, can attest. The two-to-three-uppercase-letter classname prefix standard (for example,
NSTheOther) is bad enough. But when you couple that with Apple’s overzealous penchant for capitalizing acronyms, you wind up reading
AFJSONRequestOperations from your
Class names written in that manner are undeniably harder to read. That reading lowercase letters is easier than reading all-caps is fairly well established. Moreover, when scanning over long class names, isolated capital letters make it clear when we’ve started a new word. “HTTP” is not a word, you say? I don’t care; I still want to quickly distinguish between it and “URL”.
It’s not that all-caps class names are illegible per se. It’s simply that they are less legible than they should be. It takes an extra beat or two to understand them. And I don’t know about you, but I don’t like wasting beats.
Though they’re rare, I’ve encountered programmers who voraciously favor the all-caps approach. The rationale is usually that it is, simply, proper grammar. And that’s fair enough. But guess what? It’s also proper grammar to put spaces between words, and to lowercase the first letter of non-proper nouns (unless your nouns are German). Yet we programmers happily break those grammatical decrees on a daily basis. So instead of being GrammarSticklers, we should be crafting class names to convey the classes’ meanings as clearly and quickly as possible.
Am I overreacting? IDK, maybe I am. But thanks for bearing with me anyway. I won’t waste any more of your time.
Like this story? Want to read more? Just subscribe here to get my latest stories sent directly to your inbox.
You can also support me and my writing — and get access to an unlimited number of stories — by becoming a Medium member today.