为什么 .Net 中常量不全部大写?

发布于 2024-09-24 09:23:03 字数 359 浏览 7 评论 0原文

Microsoft .Net 的命名约定将常量置于 Pascal Case 中。事实上,它明确告诉我们避免对常量使用全部大写:

您可能还需要大写 保持兼容性的标识符 具有现有的非托管符号 方案,其中全部大写 字符经常用于 枚举和常量值。在 一般来说,这些符号不应该 在装配体外部可见 使用它们。

来自 MSDN

在SO上,我发现了一些关于这个主题的问题,比如

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暖伴 2024-10-01 09:23:03

它只是一个风格指南。编程语言已经开始推荐和推动格式约定,以便代码更具可读性。

此外,被预处理器替换的符号值得特别注意——它们位于类型系统之外/之前,并且可能不是它们看起来的样子。常量只是常量,它们在编译或运行时不会改变。

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.

风尘浪孓 2024-10-01 09:23:03

因为全大写既丑陋又难以阅读,而且它是为预编译器设计的,而 .NET 甚至没有。

而且,比尔·盖茨也希望如此,而金钱永远不会错。

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.

爱的十字路口 2024-10-01 09:23:03

说全大写是丑陋的,因此不应该使用是近乎幼稚的逻辑。它来自于人们抱怨他们不习惯的事情。

从 Java 转向 C 后,我开始在变量名和函数中使用 underscores_ Between_words 。驼峰命名现在对我来说极其难看。但我仍然在 C++/Java 中使用驼峰命名法,没有抱怨,因为它很方便。

如果你不能让自己变得灵活,编程就会成为一个严厉的情妇。这就是程序员的技能。

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.

夜唯美灬不弃 2024-10-01 09:23:03

Microsoft 不遵循自己的规则,因为如果您反思 c# 4 中的新 System.Threading.Tasks 类,您将发现 LOTS_OF_CAP_CONSTANTS。

这是一种风格。我个人不介意。只要保持一致即可。

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.

满天都是小星星 2024-10-01 09:23:03

顺便说一句,EBCDIC 是 BCD(二进制编码的十进制)的扩展版本,因此当然支持小写。这是 60 年代老式和早期的 IBM 机器(和其他机器),不包含小写字母。

(当然,像 TRS-80 这样的早期家用计算机也没有小写字母)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文