.NET 指南:为什么两个字母的缩写词例外?

发布于 2024-07-17 23:08:26 字数 277 浏览 4 评论 0原文

Microsoft 的框架设计指南定义了以下内容:

“双字符首字母缩略词的两个字符都大写,除了 驼峰式标识符的第一个第一个单词”

因此,对于仅包含两个字母的首字母缩略词定义了一个例外,因为具有三个或更多字母的首字母缩略词是“正确的”驼峰式或帕斯卡式。

问题是:为什么 是否有例外,即其背后的基本原理是什么?我无法从 FDG 书籍或 Abrams 和 Cwalina 的博客中得到解释。

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.

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

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

发布评论

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

评论(5

怎樣才叫好 2024-07-24 23:08:26

他们说,如果标识符的第一部分是驼峰式大小写,那么您应该保持它的驼峰式大小写,而不是仅仅因为它是首字母缩写词而将其大写。 这是因为对您来说更重要的是能够告诉您正在处理一个参数(这正好出自相关书籍,顺便说一句我很喜欢)。

至于为什么要大写两个字符的缩写而不是三个字符的缩写,我个人不需要知道边缘情况是什么,因为我喜欢它的美感。

例如,我绝对更喜欢这个:

XmlDocument 

胜过这个:

XMLDocument

对我来说,后者有淡淡的 1982 年的味道。而且有点痛。

当然那只是我。 :)

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. :)

痴情 2024-07-24 23:08:26

为什么? 这个外壳的东西只是一个协议(以提高可读性),而不是科学!

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

咋地 2024-07-24 23:08:26

对于驼峰式大小写(第一个单词全部小写),您需要对正常的两个字母缩写例外(将第一个字母大写)进行显式例外。

否则就会出现两个相互矛盾的规则:

  • 两个字母缩写的两个字母都大写。
  • 驼峰式名称的第一个单词/缩写较低。

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.
森林散布 2024-07-24 23:08:26

因为 MS 看起来比 mS 好得多...

说真的,这些规则的目的是摆脱像 CALTextBox 这样的命名。 其中 CAL 是公司的缩写。 语言设计团队认为“CAL”太像被滥用(且很少被理解)的匈牙利表示法,而大多数程序员似乎都无法正确理解这种表示法。

因此,他们进行了一番长篇大论,以消除编程世界中的那些废话。 这是试图将其编纂成法的规则之一。

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.

苏别ゝ 2024-07-24 23:08:26

Microsoft .NET 在名称方面确实不一致。 坦率地说,你提到的这本书充满了这样的例外。

我觉得 UI 看起来比 Ui 更好。 不过ID比ID好看...

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...

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