Counter variable naming

what's better? nNodes or nodeCount

+6
naming
source share
8 answers

The second, because it is read correctly.

+11
source share

This is just a style issue. I prefer nodeCount because I find it more clear. nNodes more like a Hungarian notation, but does not consider it a count variable.

+11
source share

Whatever is compatible with the rest of your base / style guide / dev team.

+4
source share

It really depends on the accepted naming conventions of which language you use, but nodeCount more readable. If you use Java, you can use the Java Naming Guide .

+4
source share

The first in C ++, the second in C # / Java.

Although this is really a very subjective question, and the recommendations of your team / company should answer it.

+2
source share

numNodes?

+2
source share

Possible names:

  • number
  • the size
  • Length
+1
source share

It depends, but I would choose the second ( nodeCount ). If your project has a specific agreement, you must follow this agreement or discuss the agreement with your team. It may also depend on the area of ​​your application. It may be okay to follow generally accepted notations in your domain.

There are several rules that could help you make these decisions.

If something can be misunderstood, someone will be misunderstood. Eliminate the possibility of misunderstanding. The probability of misunderstanding is much less in the second sentence of nodeCount . Anyone who speaks English should understand this. The first sentence, on the other hand, depends on understanding the n prefix.

Write the best noun description at the end. Is this more of a count or more of a collection of nodes ? For further use of the variable, it is important to understand that this is a count (number), and then it is counted. Therefore nNodes worse than nodeCount .

Follow basic programming principles such as KISS (keep it simple, stupid) or "Don't write smart code. Write" embarrassingly obvious "code. Ask your mother if she understands your code. If so, you wrote good code :)

0
source share

All Articles