Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions for "number of foos" variables [closed]

Let's suppose that I need to store the number of foo objects in a variable.

Not being a native English speaker, I always wonder what's the best (= short and immediately clear) name for that var.

foo_num? num_foo? no_foo? foo_no? or something else?

The full name should be number_of_foos, but it's a bit verbose.

What's your favorite and why?

like image 761
Giacomo Avatar asked Sep 18 '10 17:09

Giacomo


People also ask

What are the naming conventions for variables?

A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign " $ ", or the underscore character " _ ". The convention, however, is to always begin your variable names with a letter, not " $ " or " _ ".

What are the 4 rules for variable names?

Variable names are case-sensitive (age, Age and AGE are three different variables) There is no limit on the length of the variable name. A variable name cannot contain spaces. The variable name cannot be any Go keywords.


1 Answers

I go for fooCount because it is straightforward, and I think the word "count" is the shortest and the best that describes it, not "number of" or the like.

I go for FOO_COUNT if it you need to store it final and static(if you don't need to change it/if it is a constant). (all caps for constants!)

I go for count and calling it by Foo.count if you really have to store it as an attribute for a class that you made, which is Foo.

readability for you and for your team!

like image 139
ironmaurus Avatar answered Sep 26 '22 00:09

ironmaurus