views:

426

answers:

5

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?

+7  A: 

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

Brian Fisher
Works for me 99% of the time.
Kev
I like it because sometimes Acronyms become words (e.g. Scuba and Laser).
Brian Fisher
It's just more legible, no doubt
Eran Galperin
It makes it possible to algorithmically find the component words.
starblue
It also makes it easier for your brain to pick out the components quickly.
Darron
+4  A: 

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).

bdukes
Yep...two letter acronyms are the fly in the ointment.
Kev
+1 - That's interesting to know, thanks.
Andrzej Doyle
+1  A: 

It may be slightly easier on the eye to have fudgeSql() than fudgeSQL(), but the latter sometimes seems more correct in certain contexts.

There will be times when you end up with an acronym and another acronym next to each other in a class name or method name, and that's not so nice. Also it's a bit easier to just to the single capital when I type, somehow. However I don't think it would be nice to have it in all cases. Certainly I/O -> IO, I would hate to see Io (a moon of Jupiter) as part of a class or method name. Maybe it is one of those things that is subjective, and depends on the acronym itself. As long as you are consistent...

One thing, in Java, with getters and setters is that with the upper-casing, your variables end up having to be:

private ACRO aCRO;

rather than the nicer

private ACRO acro;

because the generated getters and setters (in Eclipse, anyway)

void setAcro(ACRO acro)

are inconsistent with the naming convention.

void setACRO(ACRO aCRO);

If you see what I mean.

JeeBee
+1  A: 

My experience is that the Usual convention is to treat caps as word separators, ie, useSql not UseSQL. The right answer is to use whatever convention makes the code clearest, and use it consistently. As JeeBee points out, this may be affected by the assumptions of your tools.

Charlie Martin
+2  A: 

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.

P Daddy