如何命名变量:numItems或itemCount? [英] How to name a variable: numItems or itemCount?

查看:110
本文介绍了如何命名变量:numItems或itemCount?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命名变量的正确方法是什么

What is the right way to name a variable

int numItems;

vs.

int itemCount;

或常量:

public static final int MAX_NUM_ITEMS = 64;

vs.

public static final int MAX_ITEM_COUNT = 64;

推荐答案

在代码完成"中,史蒂夫·麦康奈尔(Steve McConnell)指出数字"不明确.它可以是计数,索引或其他数字.

In "Code Complete," Steve McConnell notes that "Number" is ambiguous. It could be a count, or an index, or some other number.

但是,因为经常使用Number 造成混乱,这可能是最好的 通过使用来回避整个问题 Count 表示销售总数,而 Index 表示销售总数 具体销售."

"But, because using Number so often creates confusion, it's probably best to sidestep the whole issue by using Count to refer to a total number of sales and Index to refer to a specific sale."

这篇关于如何命名变量:numItems或itemCount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆