views:

390

answers:

5

Microsofts Framework Design Guidelines define, among other things, the following:

"Do capitalize both characters of two-character acronyms, except the first first word of a camel-cased identifier"

So there is an exception defined for acronyms that comprise of only two letters, since acronyms with three or more letters are "properly" camel cased or pascal cased.

The question is: Why is there an exception, i.e. what is the rationale behind it? I could not get an explanation from the FDG book or the blogs of Abrams and Cwalina.

A: 

Because MS looks so much better than mS...

Seriously, the point of these rules was to get rid of naming things like CALTextBox. Where CAL is the acronym for a company. The language design team felt that "CAL" smelled way too much like the much abused (and little understood) hungarian notation that most programmers just can't seem to get right.

So they went on a little tirade to rid the programming world of that crap. This is one of the rules trying to codify it.

Chris Lively
I'd think it would be MS, Ms, or ms. But never mS.
g .
A: 

Microsoft .NET is really inconsistent when it comes to names. Frankly, the book you've mentioned is full of such exception.

I guess UI looks better than Ui. But Id looks better than ID...

Filip
ID is not an acronym, it comes from Identifier. That's not an exception.
legenden
+1  A: 

They're saying that if the first part of an identifier is camel-cased, you should keep it camel-cased rather than capitalizing it just because it's an acronym. That's because it's more important for you to be able to tell that, for example (and this is right out of the book in question, which I love by the way), you're dealing with a parameter.

As for why you capitalize a two-character acronym but not a three-character acronym, I personally don't need to know what the edge cases are because I like the aesthetics of it.

For example, I definitely prefer this:

XmlDocument

Over this:

XMLDocument

To me, the latter faintly smells of 1982. And it hurts a little.

That's just me of course. :)

Brian MacKay
Brian: I also prefer XmlDocument over XMLDocument and UIElement over UiElement. But I'd like to know why the MS guys decided so.
A: 

For camel case (where the first word is all lower-case), you need an explicit exception to the normal two letter abbreviation exception to capitalising the first letter).

Otherwise there would be two contradictory rules:

  • Two letter abbreviations have both letters capitalised.
  • First word/abbrevitation of a camel cased name is lower.
Richard
We should clearly distinct between abbreviations and acronyms when talking about naming conventions, like MS does. Since for abbreviations there are no exceptions made - except that you should avoid them... ;)
I tend to regard the "avoid abbreviation" as one of the rules that really does only make sense for reusable (framework, library) naming; unlike most of the guidelines which make good sense for all .NET code.
Richard
+1  A: 

Why? This casing thing is just an agreement (to improve readability), not science!

M. Jahedbozorgan