命名首选项:getSupportedModes() 与supportedModes()?
我很难决定为我的方法选择哪个名称。我认为它们都是不言自明的,但后者输入速度更快,因此,我当前的偏好是supportedModes()。你怎么认为?
I'm having hard time deciding which name to choose for my method. I think they both are pretty much self-explanatory, but the latter is faster to type, so, my current preference is supportedModes(). What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说,
getSupportedModes
意味着简单的检索,而如果涉及一些实际逻辑来解决它们,那么像defineSupportedModes
或calculateSupportedModes
可能会更好。名称应该描述该函数的作用。对于具有某种形式的自动完成功能的现代 IDE,简洁性并不是主要考虑因素。不同的语言也有自己的约定。例如,Java 中名为
calculateSupportedModes
的函数通常在 C# 或 VB 中称为CalculateSupportedModes
。To me,
getSupportedModes
implies simple retrieval, whereas if there is some actual logic involved to work them out, something likedetermineSupportedModes
orcalculateSupportedModes
may be better. The name should describe what the function does. Brevity is not a major consideration with modern IDEs with some form of autocomplete.Different languages also have their own conventions. For example, a function called
calculateSupportedModes
in Java would normally be calledCalculateSupportedModes
in C# or VB.我更喜欢更明确的 getSupportedModes。您不希望其他开发人员再次猜测该方法的作用。
I would prefer the more explicit which is getSupportedModes. You don't want other developers to second guess what the method does.
不仅仅作用于传递的参数的函数应该被命名为动作。
Functions that act on more than just their passed arguments should be named as actions.