Naming conventions for “number of foos” variables

2019-03-14 10:10发布

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?

10条回答
狗以群分
2楼-- · 2019-03-14 10:31

fooCount if the variable isn't a constant, FOO_COUNT if it is. :D

查看更多
对你真心纯属浪费
3楼-- · 2019-03-14 10:33

Since the variable stores the count of the number of foo objects, fooCount gets my vote.

查看更多
放荡不羁爱自由
4楼-- · 2019-03-14 10:37

I personally would go for total_foos or totalFoos depending on the language standard. It represents better that the value is a final total and not just a running count.

It also makes more sense to say "I have 3 total foos" rather than "I have a 3 count of foos".

Overall, it's not a huge deal but I always use total over count!

查看更多
冷血范
5楼-- · 2019-03-14 10:37

I'd go for fooCount

查看更多
登录 后发表回答