表示驼峰式类名中的缩写
我正在创建一个 C# 库,并将使用它们使用的协议(TCP、UDP 等)作为大多数公共类的前缀,但我遇到了一个两难的困境:应该是 TCPXxxx 还是TcpXxxx
?
.NET 框架中似乎没有标准(IPAddress
与 TcpClient
)。
使用库时您更喜欢哪一个:TCPXxxx
或 TcpXxxx
?
I'm creating a C# library and am going to be prefix most of the public classes with the protocol they use (TCP, UDP, etc) and I came to a little dilemma: should it be TCPXxxx
or TcpXxxx
?
There doesn't seem to be a standard in the .NET framework (IPAddress
versus TcpClient
).
Which you would prefer when working with a library: TCPXxxx
or TcpXxxx
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据设计指南,它应该是 TcpXxxx。
在设计指南中,2 个字母的首字母缩略词均大写,所有其他字母均采用 pascal 大小写。
来自 Cwalina 和 Abrams 的框架设计指南:
MSDN 有一个简短的版本。
It should be TcpXxxx, by the design guidelines.
In the design guidelines, 2 letter acronyms are capitalized, all others are pascal cased.
From Framework Design Guidelines by Cwalina and Abrams:
MSDN has an abbrieviated, shorter version of this.
我总是喜欢想象一个将 WordsLikeThis 转换为类似单词的理论过程,并想象所讨论的名称将如何转换。 一些例子:
TCPSocket -> TCP套接字
TcpSocket-> tcp-socket
显然后者更有意义。
I always like to imagine a theoretical process that converts WordsLikeThis to words-like-this, and imagine how the name in question would convert. Some examples:
TCPSocket -> t-c-p-socket
TcpSocket -> tcp-socket
Clearly the latter makes more sense.
一般来说,当它是 2 个字符的前缀时,将其保留为大写 (IPAddress);当它是 3 个字符或更多字符时,请使用 Pascal 大小写前缀 (TcpXxxx)。
此规则有一些例外(例如,如果前缀是大写的专有名称)。
Generally, when it's a 2-character prefix, leave it uppercase (IPAddress) and when it's 3 characters or more, Pascal-case the prefix (TcpXxxx).
There are a few exceptions to this rule (e.g., if a prefix is a proper name that's uppercase).
您可以考虑将这些类放在名为“TCP”的命名空间中。 如果这样做,那么该命名空间中的函数/类名称将变得更短、更清晰,并且您根本不必担心这个问题。
You might consider putting these classes in a namespace called "TCP". If you do so, then your function/class names in that namespace will get shorter and clearer and you won't have to worry about this issue at all.
我知道这是 C# 编码风格,但我更喜欢 Python PEP 8 风格
但是在罗马……一致的代码更好,这就是为什么语言风格指南是一个好主意。
I know this is C# coding style but I prefer the Python PEP 8 Style
But when in Rome...consistent code is better which is why language style guides are a good idea.
我知道在 Eclipse 中我可以通过仅使用类型名称的大写字母来快速指定类型,所以我更喜欢小写而不是大写......我不知道 VS 是否可以做同样的事情,但它是 < em>太棒了。
I know in eclipse I can quickly specify a type by using just the capitals letters of the type name so I prefer to under-capitalise rather than over-capitalise... I don't know if VS can do the same but it is fan-tastic.