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

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.

主站蜘蛛池模板: 都昌县| 米林县| 鄯善县| 沐川县| 同德县| 曲松县| 章丘市| 沂南县| 疏勒县| 高碑店市| 洪泽县| 永春县| 阿坝县| 彭州市| 涟源市| 嵩明县| 万安县| 永清县| 民勤县| 蕉岭县| 海口市| 和林格尔县| 安福县| 凤阳县| 麟游县| 邳州市| 平凉市| 上饶市| 从江县| 神池县| 诸城市| 留坝县| 香港 | 荣成市| 德昌县| 通许县| 嵩明县| 平泉县| 嵊泗县| 枝江市| 望谟县|