|
CLASS NOTES:
SD110 Computer Programming Logic |
|
VARIABLES
(Naming Conventions and Data Types) |
OVERVIEW:
|
Variables are unique names given to a specified location of memory which the programmer uses to solve the problem at hand. To the computer it is only important that each be unique, legibility of the Variable Name is irrelevant. Therefore, xxxxxxx01 and xxxxxxx02 are perfectly acceptable to the computer, but hard for us humans as we have no clue what either stands for. Instead of arbitrarily choosing a Variable Name, let's follow some rules to make it simpler to read and understand. First, there are no spaces in Variable Names. A space denotes the end of some entity so having one in a variable name will not work. It will simply cause an error and not function. Second, CAPITAL LETTERS and lower case letters are actually different characters, so the Variable Names PAYROLL, Payroll and payroll are three unique Variable Names. Be sure not to mix them up or you will end up with errors which can be hard to find. Variables can be comprised of more than one word. One way of easily
reading In addition to having a unique and telling name for your variables, most programs require that you define what Type of variable it is. There are several different Types of variables, but they mostly fall into two general groups: Characters (words, sentences, etc...) or Numbers. Sometimes the Character variables will be called Text or Strings, but they still represent the same Type of data. Examples of Good and Bad Variable Names
|