给房产最好的命名?
您会选择以下三个选项中的哪一个作为 C# 中的属性名称,为什么?
- 今年迄今工资
- YTDWages
- YTDWages
Which of the following three options would you choose for a property name in C#, and why?
- YearToDateWages
- YTDWages
- YtdWages
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我会选择 1。我不想缩写任何东西,除非它是一个非常常见的缩写词,拼写出来会很荒谬。像“HyperTextTransferProtocolRequest”这样的东西拼写出来会很荒谬,因此可以安全地将其缩写为“HttpRequest”。这有点主观,但当有疑问时,我倾向于不缩写。
如果您决定选择 2 或 3,根据“框架设计指南”的建议,我可能会投票给 3。它基本上表示,对于 3 个或更多字母长的首字母缩略词,您应该将第一个字母大写,其余字母小写。对于 2 个字母的首字母缩略词来说有点含糊...有些人喜欢将所有字母大写,例如“ID”,而有些人则喜欢使用“Id”。该指南实际上是将 2 个字母缩写词的所有字母大写,但这与 3 个以上字母缩写词的指南相矛盾,因此人们同时采用这两种方法。
I would go with 1. I prefer not to abbreviate anything, unless it's a super-common acronym that would be ridiculous to spell out. Something like "HyperTextTransferProtocolRequest" would be ridiculous to spell out, so it's safe to abbreviate that as "HttpRequest." It's a little subjective, but when in doubt, I tend to not abbreviate.
If you decide to go with 2 or 3, I'd probably vote for 3, based on the recommendations from the "Framework Design Guidelines." It basically says that for acronyms that are 3 or more letters long, you should capitalize the first letter and lower-case the rest. It's a little ambiguous on 2-letter acronyms... Some people prefer to capitalize all letters like "ID" and some prefer to go with "Id". The guideline is to actually capitalize all letters of a 2-letter acronym, but that kind of contradicts with the guideline for 3+ letter acronyms, so people do it both ways.
我会使用
YearToDateWages
,因为如果列表中没有它,我就不知道您在说什么。另请参阅 MSDN 上的一般命名准则:
强调原文。
I would use
YearToDateWages
, because without that being in the list I wouldn't know what you were talking about.See also the general naming guidelines on MSDN:
Emphasis in original.
我认为第一个是最好的,因为它是自我描述的。
I think the first one is best because it is self descriptive.
微软建议命名约定排除 #2
任何带有 > 的内容。 2 个缩写字母应该是 Xxx 而不是 XXX,
但 2 个应该是 XX
我喜欢少打字,所以我会选择 YtdWages
Microsoft suggested naming convention rule out #2
anything with > 2 acronym letters should be Xxx not XXX
but 2 should be XX
I like less typing so I would go with YtdWages
这取决于。
如果您正在创建一个可供外部使用的库,请参考 .NET Framework 设计指南 说#1 是首选。
如果它是内部应用程序/库,那么我建议使用与您的团队开发标准一致的格式。
It depends.
If you are making a library that will see external use, the .NET Framework Design Guidelines say that #1 is preferred.
If it's an internal application/library, then I recommend using the format that is consistent with your teams development standard.
我会选择全名而不是缩写词。它更具描述性,虽然“YTD”对某些人来说可能是显而易见的,但可能并非对所有人来说都是如此。 YearToDate 不算太长,含义也很明确。
I would opt for the full name rather than one featuring an acronym. It is more descriptive, and while "YTD" may be obvious to some, it might not be to everyone. YearToDate is not excessively long and the meaning is clear.
您有理由不使用第一个吗?
这不仅是为了别人,也是为了别人。如果两年后您必须更改自己的代码中的某些内容,好的描述性名称会对您有所帮助。
Is there a reason why you would not use the first one?
It is not only for others; if you have to change something in your own code 2 years later, good, descriptive names will help you.
.Net 框架似乎主要遵循#1。所以我会坚持下去。应避免使用缩写,除非在课堂上非常常见。当然,对于本地(函数)变量来说,这不那么严格,我想说缩写和短名称更合适,以使代码更小、更简洁。
好的缩写的例子有 XML 和 HTTP。谁认真去写
The .Net framework seems to follow mostly #1. So I would stick with it. Abbreviations should be avoided except where extremely commonly known at the class level. Of course for local(function) variables this is much less strict and I would say that abbreviations and short names are much more appropriate so as to make the code smaller and more concise.
Examples of good abbreviations are XML and HTTP. Who is seriously going to write
我也投票给1号。
很少有时候您不想要一个描述性的名称。
Visual Studio 将帮助您处理长名称。
半题外话注:
如果你找不到合适的名字......也许计划的用途毕竟不是那么清楚;)
I vote for number 1 as well.
There will be very few times when you do NOT want a descriptive name.
Visual Studio will assist you with the long names.
Semi off topic note:
If you cant find a suitable name... perhaps the planned usage is not that clear after all ;)