C# 变量名 corpID 与 corpId
我正在尝试确定 C# 中的局部变量是否应命名为“corpID”或“corpId”。
看到区别了吗? “d”应该是大写还是小写?
也考虑一下这个:
customerPK vs. customerPk
如果在末尾添加另一个词会更重要。像这样:
customerPKField 与 customerPkField
看到我的 delima 了吗?有没有一种广泛采用的方法来处理这个问题?
I'm trying to determine if a local variable in C# should be named "corpID" or "corpId".
See the difference? Should the "d" to be upper case or lower case?
Consider this one also:
customerPK vs. customerPk
It matters more if another word is added the end. Like this:
customerPKField vs. customerPkField
See my delima? Is there a widely adopted way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
来自 http://msdn.microsoft.com/en-us/library/ms229043 .aspx:
`注意:
标识符中可以使用的两个缩写是 ID 和 OK。在 Pascal 大小写的标识符中,它们应显示为 Id 和 Ok。如果用作驼峰式标识符中的第一个单词,它们应分别显示为 id 和 ok。
From http://msdn.microsoft.com/en-us/library/ms229043.aspx:
`Note:
The two abbreviations that can be used in identifiers are ID and OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as id and ok, respectively.`
大写约定 msdn.microsoft.com/en-us/library/ms229002.aspx" rel="nofollow noreferrer">名称指南 说:
如果这是类或结构的公共接口的一部分,这表明 corpId 是正确的。
但是,如果这是传递给方法的参数,则适用驼峰式大小写规则,并且:
因此,您可以使用 corpID 作为参数名称。
(就我个人而言,我觉得这很奇怪,并且总是使用 corpId,但这是实际的官方指南......)
The Capitalization Conventions in the Guidelines for Names says:
This would suggest that corpId is correct, if this is part of the public interface of a class or struct.
However, if this is a parameter being passed into a method, then camel casing rules apply, and:
So, as a parameter name, you'd use corpID.
(Personally, I find this odd, and always use corpId, but this is the actual official guideline...)
这是 “ID”(任何标识)的 .NET 命名约定的重复项:大写)
从那里接受的答案,
This is a duplicate of .NET naming convention for "ID" (anything identification: Capitalization)
From the accepted answer there,
每次都小写。有时它看起来真的很奇怪,但它胜过另一种选择:通过始终决定是否资本化,你会创造相对更多的奇怪/不一致之处。
Lower case every time. It will look really odd sometimes, but it beats the alternative: your creating comparatively more oddities/inconsistencies by making the decision all the time about whether or not to capitalize.
对于corpId,我个人偏好是corporationId。您已经拼出了整个单词,因此它不会与“Id”部分混淆。
但是,您应该决定自己更喜欢什么并保持一致。如果你在一个团队中,但与团队保持一致。
For corpId, my personal preference is corporationId. You've spelled out the entire word, so it won't get confused with the "Id" part.
However, you should decide what you like better and be consistent. If you're on a team, but consistent with the team.
我会使用 Id 和 Pk 作为名称。实际上MSDN上有一个关于大写的主题 http://msdn.microsoft.com /en-us/library/ms229043.aspx
I'd use Id and Pk for names. Actually there is a topic about capitalization on MSDN http://msdn.microsoft.com/en-us/library/ms229043.aspx
.NET 命名约定允许使用两个字符的缩写,例如 ID。
最重要的是在整个项目/解决方案中保持命名方案一致。不要在这里使用
Id
那里使用PK
,或者更糟糕的是,混合使用Pk
和PK
。现在,由于我总是写
Id
,所以我也以严格的 .NET 风格保留所有其他缩写:Pk
编辑:
The .NET naming convention allows for two-character abbreviations like ID.
The most important thing is to keep you naming scheme consistent across the whole project/solution. Don't use
Id
here andPK
there, or even worse, mixPk
andPK
.Now since I always write
Id
I also keep all other abbreviations in strict .NET style:Pk
Edit:
是的,有命名指南。请参阅 http://msdn.microsoft.com/en-us/library/ms229002 .aspx 一般而言,以及 http://msdn.microsoft。 com/en-us/library/ms229043.aspx 用于大写。
您的特定“corpID”问题的答案很可能是“corporateId”,具体取决于“corp”到底代表什么。
Yes, there are guidelines for naming. See http://msdn.microsoft.com/en-us/library/ms229002.aspx in general, and http://msdn.microsoft.com/en-us/library/ms229043.aspx for capitalization.
The answer to your particular "corpID" question is most likely "corporateId", depending on exactly what that "corp" is meant to represent.
这确实更符合公司标准。在我的团队中,这是可以接受的,并且最好缩写(例如 ID)始终保持相同的大小写。例如,如果您有 idCard 或 cardID,它始终保持相同的外壳。但一些团体认为,为了可读性,它应该只是第一个字母。一切都取决于个人喜好...
This really falls more into company standards. Within my team it is acceptable, and preferred that abbreviations (such as ID) remain the same case all the way through. So for instance if you have idCard or cardID it always remains with the same casing. But some groups believe it should be only the first letter for readability. All comes to personal preference...
选择你喜欢的任何东西,但要保持一致。这是做出“错误”决定总是比不做决定和过度讨论这件事要好的情况之一。
Choose whatever you like, but be consistent. This is one of the cases where taking a "bad" decision is always better than taking no decision and over-discuss this thing.
在 .NET 的命名建议中,两个字符的首字母缩略词应为大写,而具有三个或更多字母的首字母缩略词应为 pascal/camel 大小写。
这将为您提供 customerPK 和 customerPKField,因为 PK 是缩写词,但使用 Id/ID 则更难。它真的是缩写吗?为了我的身份?我总是使用 Id 而不是 ID。
In the naming recommendations for .NET it says that two character acronyms should be upper case while acronyms with three letters or more would be pascal/camel case.
That would give you customerPK and customerPKField as PK is an acronym, but with Id/ID that is harder. Is it really an acronym? For I-Dentity? I always use Id rather than ID.
系统地将标识符中的每个单词甚至首字母缩略词或缩写词恢复为小写的优点是,它使单词分离,从而使标识符的阅读更容易。
这样做的缺点是,首字母缩略词和缩写词,特别是当它们很短(例如 IO 或 ID)时,一开始可能看起来有点奇怪。
我个人的偏好是仅将每个单词、首字母缩略词、缩写词的首字母大写(除了第一个单词,如果使用驼峰命名法)。也就是说,
无论你选择什么,真正重要的是它应该是一致的;公司通常在命名和其他实践方面有他们希望程序员遵循的约定。一般趋势是避免使用缩写,除了最广为人知和接受的缩写(例如 ID,当然还有会计/公关申请中的 SSN)。
The advantage of systematically returning to lowercase with each word or even acronym or abbreviations within an identifier is that it makes word separation and hence identifier reading easier.
The drawback of doing so it that said acronyms and abbreviations, in particular when they are short like IO or ID may look a bit odd at first.
My personal preference is to only UpperCase the initial letter of each word, acronym, abbreviation (except for the very first word, in case of camelCasing). That is
No matter what you opt for, what really matters is that it should be consistent; companies often have conventions they like the programmers to follow in the area of naming as well as other practices. The general trend is to avoid abbreviations, except the most widely known and accepted ones (say ID, for sure and SSN in the context of an accounting/PR application).
我想说,无论你选择什么惯例,都不要把它变成某种宗教事物。只是不值得打扰......(我并不是说编码指南毫无用处,只是我认为这个特定问题不是很重要)。
这并不是说
corporationId
比corporationID
更清晰或更不清晰,不是吗?I'd say, whatever convention you choose, don't make this into some religious thing. It's just not worth bothering... (I'm not saying that coding guidelines are useless, just this particular issue I consider not very important).
It's not that
corporationId
is any clearer or less clear thancorporationID
, is it?