Thursday, March 31, 2011

Variable, Subroutine and Function Names



In the next chapter you will be introduced to variables, subroutines and functions. As the programmer you get to choose and assign the names. The names of the variables and functions must follow these simple rules.

  • The first character must be a letter of the alphabet (lowercase or uppercase).
  • The name can contain an underscore “_”, but NOT start with an underscore.
  • You CANNOT use a number as the first character of the name.
  • Names CANNOT contain spaces.
  • Names CANNOT match any of the reserved words.

 The following are examples of valid names:
x
add_two_num
x13

We recommend that you use descriptive names for your variables and your functions and that you adopt a standard way of naming things. The two formats that are common are; using the underscore to replace spaces, or capitalizing the first letter of complete words after the first word in the name. For example:

add_two_num
addTwoNumbers

No comments:

Post a Comment