Bruno Brant
Bruno Brant

Reputation: 8564

Why aren't constants all in upper-case in .Net?

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?

Upvotes: 9

Views: 6085

Answers (5)

Peter Smith
Peter Smith

Reputation: 11

Just as a BTW -- EBCDIC is the extended version of BCD (binary coded decimal), and as such certainly supports lower case. It's the 60s vintage and earlier IBM machines (and others) that did not include lower case.

(And, of course, early home computers like the TRS-80 didn't have lower case, either)

Upvotes: 1

Pizzach
Pizzach

Reputation: 87

Saying that all caps is ugly and thus should not be used is borderline childish logic. It comes from people complaining about what they are not used to.

Having gone from Java to C, I started using underscores_between_words in variable names and functions. camelCase is extremely ugly to me now. But I still use camelCase for C++/Java without complaining because it is convension.

If you can't make yourself flexible, programming will become a harsh mistress. That is the skill of a programmer.

Upvotes: 5

Bear Monkey
Bear Monkey

Reputation: 521

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.

Upvotes: 3

Steven Sudit
Steven Sudit

Reputation: 19640

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.

Upvotes: 4

user318904
user318904

Reputation: 3076

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.

Upvotes: 10

Related Questions