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

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.

主站蜘蛛池模板: 亳州市| 太白县| 江西省| 霍州市| 灯塔市| 徐水县| 济宁市| 石狮市| 溧水县| 平凉市| 来安县| 临城县| 孟津县| 蒙城县| 渭源县| 岳西县| 银川市| 东平县| 新竹县| 灌南县| 新昌县| 三穗县| 富阳市| 汝城县| 周至县| 高台县| 策勒县| 如皋市| 娄烦县| 荆州市| 花莲县| 锡林郭勒盟| 于都县| 昌都县| 新和县| 夏河县| 玉溪市| 易门县| 宽城| 武安市| 霸州市|