Wednesday, April 6, 2011

Naming a count variable

Hey Stack overflow

what's better? nNodes or nodeCount

From stackoverflow
  • 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.

    ShreevatsaR : If your code convention is that "nSomething" always stands for "number of somethings", you don't need to say again that it's a count variable.
    Hosam Aly : Yes @ShreevatsaR, I agree with you. But if there is no convention (yet) then nodeCount seems clearer (to me).
  • The second, since it reads properly.

  • 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 ?

  • Avoid putting "count" into variable names, too easy to get an obscene typing error.

    dan04 : I don't think I've made that particular typing error, but I have gotten the "public" keyword wrong too many times.

0 comments:

Post a Comment