方法/类/包的命名约定
您对日常代码使用什么命名约定?我正在思考这个问题,因为我目前有一个 Python 项目,其中包含 3 个包,每个包都有独特的用途。现在,我已经将通用的“实用”方法放入我为该项目创建的第一个包中,但是我正在考虑将这些方法移动到单独的包中。问题是我该怎么称呼它?实用、收藏、什锦?
您是否有任何标准的命名约定,如果有,请提供链接吗?我知道每种语言都有自己的命名约定,但是您认为最有用的特定语言是否建议我开始使用?
What naming conventions do you use for everyday code? I'm pondering this because I currently have a project in Python that contains 3 packages, each with a unique purpose. Now, I've been putting general-purpose, 'utility' methods into the first package I created for the project, however I'm contemplating moving these methods to a separate package. The question is what would I call it? Utility, Collection, Assorted?
Is there any standard naming conventions you swear by, and if so can you please provide links? I'm aware each language has it's own naming conventions, however is there any particular one that you find the most useful, that you'd recommend I'd start using?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,您应该遵循您所使用的语言的命名约定。您是否喜欢或偏爱另一种语言的标准并不重要。语言上下文中的一致性有助于使您的代码更易于他人阅读、维护和使用。在 Python 中,这意味着您使用 PEP 8。
使用个人示例:
在 Python 中,我将包称为“utils”——或者如果我打算重新分发,则将其称为“coryutils”或类似的名称以避免命名空间冲突。
在 Java 或 ActionScript 中,我将包称为“net.petosky.utils”,无论我是否打算重新分发。
In general, you should follow the naming convention of the language you're using. It doesn't matter if you like or prefer the standards of another language. Consistency within the context of the language helps make your code more readable, maintainable, and usable by others. In Python, that means you use PEP 8.
Using a personal example:
In Python, I'd call the package "utils" -- or if I intended on redistribution, "coryutils" or something similar to avoid namespace collisions.
In Java or ActionScript, I'd call the package "net.petosky.utils", regardless of whether I intended on redistribution or not.
除非您有充分的理由不这样做,否则您应该遵循 PEP 8< 中提供的指南/a>.特别参见“规定:命名约定”。
Unless you have some good reason not to, you should follow the guidelines presented in PEP 8. See, in particular, "Prescriptive: Naming Conventions".