what's better? nNodes or nodeCount
8 回答
The second, since it reads properly.
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.
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.
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 ?
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 then nodeCount
.
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:
- count
- size
- length