命名约定:动词/名词和英语语法使用指南
谁能给我指出一个网站,或者给我一些关于如何为接口、类甚至与该对象或方法的用途相关的方法和属性选择名称的智慧?
这是专门针对 Microsoft 开发的,因此并未真正使用 Java 风格的“doGet”等,但是必须(我认为)存在一些跨越语言障碍的通用规则。
一个例子可能会有所帮助:我有 4 个接口名称可供选择:
IGroupedItem
IGroupableItem
IDataEntity
IGroupedEntity
它们都包含一个形容词和名词,或者只包含一个名词。 看看 .NET 框架,似乎必须有某种规则集,以保持一致性? 除了明显的方法动词之外。
编辑:虽然示例是一个接口,但我并不将其仅限于接口。 一般准则是类是名词,方法是动词,属性是名词。 我想我的意思是同义词的选择。 到处乱扔“实体”是错误的吗
Can anyone point me to a site, or give me some wisdom on how you go about choosing names for interfaces, classes and perhaps even methods and properties relating to what that object or method does?
This is specifically for Microsoft development, so Java-esque "doGet" and so on isn't really used, however some general rules that cross language barriers must (I would've thought) exist.
An example might help: I have 4 choices of names for an interface:
IGroupedItem
IGroupableItem
IDataEntity
IGroupedEntity
They all contain an adjective and the noun, or just a noun. Looking at the .NET framework it seems like there must be some kind of ruleset for this, for consistency? Aside from the obvious verbs for methods.
Edit: Though the example is an interface, I'm not limiting this to just interfaces. The general guideline is classes are nouns, methods verbs, properties nouns. I suppose what I mean is choice of the synonym. Is throwing "Entity" everywhere wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
有关命名指南,请参阅 MSDN 文章。 简而言之:
对于您的示例 - IGroupableItem。
Look at the MSDN articles for naming guidelines. In short:
For your example - IGroupableItem.
接口是类能够做的事情。 不是它是什么,而是它能做什么。
其他名称描述事物是什么或太模糊而无用。
具体来说,“IDataEntity”基本上没有意义。 毕竟,一切都是数据实体。
Interfaces are things a class is capable of doing. Not what it is, but what it can do.
Other names describe what things are or are too vague to be useful.
Specifically, "IDataEntity" is largely meaningless. After all, everything's a data entity.
MSDN 有一篇关于接口命名指南的文章这可能会帮助你。 如果您想要接口以外的东西的命名约定,以及许多其他命名和设计指南,您也可以在 MSDN 上找到这些内容。
MSDN has an article just on Interface Naming Guidelines that may help you out. If you want the naming conventions of stuff other than interfaces, along with many other naming and design guidelines, you can find that all on MSDN, too.
这与 Spodi 的答案相同,但 MSDN 的类库开发人员的设计指南< /a> 大部分都很优秀,涵盖命名等等。
This is the same material as Spodi's answer, but MSDN's Design Guidelines for Class Library Developers are mostly excellent, covering naming and much, much more.
有一篇不错的文章
让错误的代码看起来错误
作者:乔尔·斯波尔斯基。 它讲述了不太流行但非常方便的命名约定。
There is nice article
Making Wrong Code Look Wrong
by Joel Spolsky. It tells about not so popular, but very handy naming convention.
除了 MSDN 指南之外,Juval Lowy 的 IDesign 提供了一份 C# 编码标准文档,该文档非常有帮助(不知道这与 MSDN 是否/有多大不同)。
C# 编码标准
As well as the MSDN Guidelines, there is a C# Coding Standards document from IDesign by Juval Lowy that is quite helpful (don't know if/how much this differs from MSDN).
C# Coding Standards
对于函数(等)名称中的动词,通常使用动词的原始形式,例如
Handle
、ExecuteQuery
或IsAny
, ...一些不太常见的动词用法使其与
s/es
成为单数,例如ProducesResponseType
(MS 文档)。For verbs in function (and etc.) names, it's common to use the original form of the verb, like
Handle
,ExecuteQuery
, orIsAny
, ...Some less common usage of verbs makes it singular with
s/es
, likeProducesResponseType
(MS Docs).试试这个....
主站点:http://www.ssw.com .au/ssw/standards/Default.aspx
代码规则:http://www.ssw.com.au/ssw /标准/规则/RulestoBetterCode.aspx
Try this....
Main Site: http://www.ssw.com.au/ssw/standards/Default.aspx
Code Rules: http://www.ssw.com.au/ssw/Standards/Rules/RulestoBetterCode.aspx