命名计数变量
什么更好? nNodes 或 nodeCount
what's better? nNodes or nodeCount
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
什么更好? nNodes 或 nodeCount
what's better? nNodes or nodeCount
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
第二个,因为它读起来正确。
The second, since it reads properly.
这只是一个风格问题。 我更喜欢
nodeCount
因为我发现它更清晰。nNodes
更类似于匈牙利表示法,但并没有说它是计数变量。This is simply a style issue. I prefer
nodeCount
because I find it clearer.nNodes
is more similar to Hungarian notation, but doesn't say it's a count variable.无论哪个与您的代码库/风格指南/开发团队的其他部分一致。
Whichever is consistent with the rest of your code base / style guide / dev team.
这实际上取决于您所使用的语言所接受的命名约定,但
nodeCount
更具可读性。 如果您使用的是 Java,则可以使用 Java 命名约定 指导。It really depends on the accepted naming conventions of whichever language you are using, but
nodeCount
is more readable. If you are using Java, you can use the Java Naming Conventions guide.第一个是 C++,第二个是 C#/Java。
尽管这确实是非常主观的问题,应该由您的团队/公司指南来回答。
The first one in C++, the second one in C#/Java.
Though this is really very subjective question and should be answered by your team/company guidelines.
节点数?
numNodes ?
这取决于,但我会选择第二个(
nodeCount
)。 如果您的项目定义了特殊约定,您应该遵循此约定或与您的团队讨论该约定。 它还可能取决于您的应用程序的领域。 遵循您所在领域中普遍接受的符号可能没问题。有一些规则可以帮助您做出此类决定。
如果某件事可能被误解,那么它就会被某人误解。 消除误解的可能性。
第二个建议
nodeCount
中产生误解的可能性要小得多。 每个说英语的人都应该明白。 对方的第一个建议取决于对n前缀的理解。在最后写下最好的描述性名词。
它更多的是计数还是更多节点集合? 为了进一步使用该变量,更重要的是要了解它是一个计数(数字),而不是计数的内容。 因此,
nNodes
比nodeCount
更糟糕。遵循基本编程原则,例如 KISS(保持简单、愚蠢)或“不要编写聪明的代码。编写‘明显得令人尴尬’的代码。”询问你的母亲是否理解你的代码。 如果她这样做了,那么你就写了很好的代码:)
It depends, but i would choose the second one (
nodeCount
). If your project have defined a special convention you should follow this convention or discuss the convention with your team. It also could depend on the domain of your application. It could be ok to follow general accepted notations in your domain.There are some rules which could help you to do decisions like this.
If something could be misunderstood it will be misunderstood by someone. Eliminate the possiblity of misunderstanding.
The chance of misunderstanding is way less in the second suggestion
nodeCount
. Everyone who speaks english should understand it. The first suggestion on the other side depends on the understanding of the n prefix.Write the best describing noun at the end.
Is it more a count or more a collection of nodes ? For further use of the variable it is more important to understand that it is a count (a number) then what is counted. Therefore
nNodes
is more bad thennodeCount
.Follow basic programming principles like KISS (Keep it simple, stupid) or "Don’t write clever code. Write 'embarrassingly obvious' code." Ask your mother if she understand your code. If she did then you have written good code :)
可能的名称:
Possible names: