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
GetNumberOfObjects
GetObjectCount
Who can tell me what the subtle differences are between them?
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
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
So, IMHO the best variant is 'GetObjectCount' here, of course if it returns the quantity of object.
Use whatever you want, but use it consistently.
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.
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