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?
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 " _ ".
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With