views:

109

answers:

4

Microsoft naming conventions for .Net put constants in Pascal Case. In fact, it explicitly tells us to avoid using all caps for constants:

You might also have to capitalize identifiers to maintain compatibility with existing, unmanaged symbol schemes, where all uppercase characters are often used for enumerations and constant values. In general, these symbols should not be visible outside of the assembly that uses them.

From MSDN.

On SO I found some questions on the subject, like this one, but I couldn't find a rationale. So, anyone know or have a reference that points to why MS chose this convention?

A: 

I'm sorry, but... they're just following Rule 40.

Supuhstar
now i know what rick rolled means :-)
pm100
+2  A: 

Its just a style guideline. Programming languages have started to recommend and push formatting conventions so that code is more readable.

Also, symbols that get substituted by the preprocessor deserve special attention-- they live outside/before the type system and may not be what they appear to be. Constants are just constants, they won't change at compile or runtime.

If you think about the history, uppercase was used for C preprocessor symbols, so when C++ came out and had `const`, those symbols were kept mixed case. C# and Java both come from C++, so they follow the C++ convention.
Steven Sudit
On a side note, let's not forget that a `const` is purely compile-time while a `static readonly` is there at runtime, which is why only the former is allowed as a default value in C# 4.
Steven Sudit
On second reading, I have a nit to pick: the purpose of naming standards and formatting conventions isn't just to make code more readable but to make it mutually intelligible. There's no great reason why .NET recommends MixedCase for methods instead of camelCase, but if everyone uses the same one of these two choices, we can read each other's code without getting confused or annoyed. It's like driving on the right side of the street instead of the left: doesn't really matter, so long as everyone picks the same side.
Steven Sudit
Yes I agree, and that was my intention, "more readable", by others, not just the original author. If people are not having to constantly adjust to different styles they can absorb the semantics of the code quicker-- especially if it was not written by them. And this is a stance taken by C# and Python notably, greater gains (for everyone) are realized from a consistent style than allowing the flexibility of any style like C/C++.
+5  A: 

BECAUSE ALL-UPPERCASE IS UGLY AND HARD TO READ AND IT'S INTENDED FOR THE PRECOMPILER, WHICH .NET DOESN'T EVEN HAVE.

Also, Bill Gates wants it that way, and money is never wrong.

Steven Sudit
Stole the "ugly" from Bennor; giving credit.
Steven Sudit
And with Resharper (maybe even VS) you can type MCVTNC for MyConstantValueThatNeverChanges, but that won't work for all caps.
PostMan
I don't think that the acronym works in the selection list, at least not for VS 2008.
Steven Sudit
A: 

Microsoft doesn't following its own rules because if you reflect over the new System.Threading.Tasks classes in c# 4 YOU_WILL_FIND_LOTS_OF_CAP_CONSTANTS.

Its a style thing. Personally I don't mind. Just be consistent.

Bear Monkey