C# 缩写词的命名约定
关于 C# 缩写词的命名,如果我正在编写一个与 Windows API 相关的库,是否有针对 WindowsApi 或 WindowsAPI 的强烈约定,或者这只是个人偏好?
Regarding C# naming for acronyms, if I was writing a library related to the Windows API is there any strong convention toward either WindowsApi or WindowsAPI or is it just personal preference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
有一个约定,它指定所有长度超过 2 个字符的首字母大写,其余小写。因此
HttpContext
和ClientID
。There is a convention, and it specifies initial uppercase, the rest lowercase, for all acronyms that are more than 2 characters long. Hence
HttpContext
andClientID
.“框架设计指南”第二版,作者:Krzysztof Cwalina 和 Brad Abrams,第 40 页- 42
3.1.2 首字母缩略词大写
DO 将双字符首字母缩略词中的两个字符都大写,除了驼峰式标识符的第一个单词。
DO 仅将包含三个或更多字符的首字母缩略词的第一个字符大写,驼峰式标识符的第一个单词除外。
请勿在驼峰式标识符的开头大写任何首字母缩略词的任何字符,无论其长度如何。
"Framework Design Guidelines" 2nd edition by Krzysztof Cwalina and Brad Abrams pp.40-42
3.1.2 Capitalizing Acronyms
DO capitalize both characters on two-character acronyms, except the first word of a camel-cased identifier.
DO capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier.
DO NOT capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier.
老问题,新答案。
根据 .NET 4 首字母缩略词大写规则:
Old question, new answer.
According to .NET 4 Capitalization Rules for Acronyms:
查看 Microsoft 的官方文档 命名指南和大写约定:
Check Microsoft's official docs on Naming Guidelines & Capitalization Conventions:
我听说你应该避免缩写,所以它会变成
WindowsApplicationProgrammingInterface
。更严重的是(人们似乎误读了上面的内容,尽管下面引用了),此页面 说:
由于 API 被认为是众所周知的首字母缩略词,因此如果您想遵循指南,则可以选择名称
WindowsApi
。I've heard that you should avoid abbreviations, so it would become
WindowsApplicationProgrammingInterface
, then.More seriously (folks seem to be mis-reading the above, despite the quote below), this page says:
Since API is considered a well-known acronym, the name
WindowsApi
is the one to pick if you want to follow the guidelines.其个人喜好。但 .NET 将使用
WindowsApi
。它类似于TcpClient
的命名。Its personal preference. But .NET would use
WindowsApi
. It is akin to the naming ofTcpClient
.这只是个人(或组织)偏好。只要你保持一致,就没有问题。
.NET Framework 本身将使用WindowsApi。
It's all just personal (or organizational) preference. As long as you're consistent, you'll be ok.
The .NET Framework itself would use WindowsApi.
也看看 FxCop。这是一个很好的实用程序,可以帮助解决此类问题。
Take a look at FxCop too. It's a nice utility that will help with issues like this.