11

what's better? nNodes or nodeCount

4

8 回答 8

15

The second, since it reads properly.

于 2009-02-14T06:55:28.340 回答
13

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.

于 2009-02-14T06:55:25.967 回答
4

Whichever is consistent with the rest of your code base / style guide / dev team.

于 2009-02-14T06:55:53.877 回答
4

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.

于 2009-02-14T06:56:44.513 回答
2

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.

于 2009-02-14T07:04:52.700 回答
2

numNodes ?

于 2009-02-14T07:09:02.503 回答
2

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 :)

于 2017-12-02T15:43:09.780 回答
1

Possible names:

  • count
  • size
  • length
于 2016-08-12T10:23:18.567 回答