开发者

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?


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.


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.


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.


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜