Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capitalise acronyms in entity names?

Let's for a moment assume that you're programming in a language that uses camelcase words for identifiers, by convention. All you Ruby types with your underscore-separated method names get to sit this one out.

What approach do you take to capitalising the letters after the first when your name contains an acronym? For example, would you call a method createSQLBuffer or createSqlBuffer? Do you have a policy in place dictating what to do in this situation? Moreover, can anyone link me some articles advacating one or the other specifically, or in fact anything that covers this at all?

I know it's not really a big deal, but for some reason I sometimes come across a method/class/variable capitalised one way and thing it would look more natural the other. The strange thing is that I'm not even sure it's consistent; it would not surprise me to discover that I like all uppercase for certain names, and lowercased for others.

Anyone want to share their opinions on this?

like image 702
Andrzej Doyle Avatar asked Jan 09 '09 17:01

Andrzej Doyle


3 Answers

I'm a fan of treating Acronyms as one word when capitalizing so I like createSqlBuffer.

like image 71
Brian Fisher Avatar answered Oct 28 '22 08:10

Brian Fisher


The .NET naming guidelines (even though it's pascal cased) suggest only capitalizing the first letter in an acronym, unless it's a two letter acronym (so, createSqlBuffer, but createIOBuffer).

like image 4
bdukes Avatar answered Oct 28 '22 07:10

bdukes


IMO, capitalizing only the first letter of an acronym makes sense when camel casing, if only because capitalizing the entire word breaks the camel-casing behavior. The capital letters in a camel-cased word are supposed to indicate the start of each word, not to follow casing normal English casing rules. If you upper-case an entire acronym, you lose the clear separation between the end of the acronym and the beginning of the next word.

It's also easier to type (and slightly nicer on the eyes) with only one capital.

I agree about IO and most other two-letter abbreviations, though. I would usually leave them capitalized, even considering the above. In the end, it's really about what's easier to read.

like image 3
P Daddy Avatar answered Oct 28 '22 06:10

P Daddy