官术网_书友最值得收藏!

Naming variables

Using the right name for a variable is important. There are some conventions and some syntactical rules to name variables properly. Variables have to be one word, they have to start with a letter or underscore, and all remaining characters must be a letter, a number, or an underscore. If these rules are not followed, the program will produce an error.

There are two best practices to take into account when choosing a variable name. First, the variable name should reflect its function in the program. This makes it easier to keep track of how the program functions. Second, if the variable name consists of several words, these should be separated using either camel case or snail case to make it easier to read.

In camel case, the first word starts with a lowercase letter, while all the following words start with an uppercase letter. In snail case, each word is lowercase and is separated by an underscore. It is best practice to use either one or the other for a given program and stick with it, though this can get tricky, especially if multiple people are working on the same project.

Variables are a key part of what makes programming an effective means of expression. Storing and labeling data can make it easier to reference and keep track of, but it also makes it possible to build more sophisticated operations. This will become clear when I introduce compound statements later in this chapter.

主站蜘蛛池模板: 北京市| 兴义市| 南投县| 武安市| 台湾省| 都江堰市| 禹州市| 上栗县| 乐都县| 襄樊市| 左云县| 习水县| 阿拉善左旗| 昭觉县| 襄垣县| 鹤岗市| 延吉市| 潮州市| 宁河县| 隆化县| 明光市| 正蓝旗| 沅陵县| 监利县| 榆中县| 镇宁| 竹北市| 师宗县| 海南省| 蓬溪县| 台湾省| 金塔县| 会理县| 齐齐哈尔市| 望奎县| 清水河县| 沭阳县| 锡林郭勒盟| 湄潭县| 南靖县| 玉田县|