开发者

Which is the best among GetCountOfObjects, GetNumberOfObjects, and GetObjectCount?

I am a C++ programmer from a non-English country.I am always confused about how to choose one of the following function names:

GetCountOfObjects
开发者_StackOverflow社区
GetNumberOfObjects

GetObjectCount

Who can tell me what the subtle differences are between them?


I'm also a programmer from non-English country, but I think the best way to choose the name is

  1. use the name that is the most clear
  2. use the shortest name enough to understand easily
  3. Also, english language suppose that it's better to swap the order than use 'Of'.

So, IMHO the best variant is 'GetObjectCount' here, of course if it returns the quantity of object.


GetNumberOfObjects probably sounds closest to natural English. GetCountOfObjects sounds slightly awkward. Other than that, there is almost no difference.

My personal style would probably be to use GetNumberOfObjects for a method that just returns a known number, but CountObjects for a method that actually performs the counting.

EDIT: The reason for this difference, at least to me, is that the word 'number' is more commonly used as a noun while 'count' is more commonly used as a verb.

Really, this is a style choice. Use whatever you choose consistently and it will be fine.


Use whatever you want, but use it consistently.


I would go for the shortest simplest: size() if it makes sense. That is, if you are trying to add a member function to a class that somehow resembles a container, using the same names that are used in existing libraries for the same concepts will make code simpler to read.

Even if that does not make sense, while in Java getters and setters are common, in many C++ libraries the same function names will drop the get part and provide a shorter name: GetNumberOfObjects => NumberOfObjects, GetObjectCount => ObjectCount... If you want to make your object different from containers (and thus you explicitly want to avoid size()) I would probably go for objectCount or numObjects. While numObjects is not proper english it is easy to read and interpret and it is short.


use whichever u feel comfortable wid but be consistent wid it.avoid very long names as u can err.also u can use sum kind of distinction in d names 2 help u figure out type of variable or whether it is static,local or public or private

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜