变量被用于更复杂的

来源:互联网 发布:室内设计画图软件 编辑:程序博客网 时间:2024/05/22 08:20

在本教程中我们将使用intercapped的方法,因为它更容易这很容易错误下划线在密集的代码块的空间

第二,这也许是最重要的规则,让你的标识符名称实际上描述它们是什么。这是没有经验的程序员进行变量名称尽可能短的典型,是为了节省打字或因为他们图的意义是显而易见的。这是几乎总是错误的。理想的情况下,应命名的变量的一种方式,可以帮助那些不知道你的代码并能找出尽快。3个月后,当你看着你的节目,你会忘记它是如何工作的,你会感谢你自己挑选的有意义的变量名。代码的变量被用于更复杂的它需要有更好的名字

1
2
3
4
5
intmy_variable_name; // correct (separated by underscores)
intmyVariableName; // correct (intercapped)
 
intmy variable name; // incorrect (spaces not allowed)
intMyVariableName; // incorrect (should start with lower case letter)

1
2
3
4
5
intvalue; // correct
 
intValue; // incorrect (should start with lower case letter)
intVALUE; // incorrect (should start with lower case letter)
intVaLuE; // incorrect (see your psychiatrist) ;)

If the identifier is a multiword name, there are two common conv

注:这是用平凡的变量的名称,一个平凡的使用变量好,如循环变量。我们会解决这个问题的一节中的流量控制

第三,一个明确的评论可以走很长的路。例如,说我们已经声明了一个变量命名numberofchars,应该是存放在一个块的文本的字符数。文本“Hello World“10,11,或12个字?这取决于我们是否包括空格或标点符号。而不是numberofcharsincludingwhitespaceandpunctuation命名的变量这是相当漫长的一个好的注释声明行上应该帮助用户找出


0 0