What Is variables and rules in naming variable
Variables in a computer program are analogous to "Buckets" or "Envelopes" where information can be maintained and referenced. On the outside of the bucket is a name. When referring to the bucket, we use the name of the bucket, not the data stored in the bucket. Show Variables are "Symbolic Names". This means the variable "stands in" for any possible values. This is similar to mathematics, where it is always true that if given two positive numbers (lets use the symbols 'a' and 'b' to represent them): a + b > a (i.e., if you add any two numbers, the sum is greater than one of the numbers by itself). This is called Symbolic Expression, again meaning, when any possible (valid) values are used in place of the variables, the expression is still true. Another example, if we want to find the sum of ANY TWO NUMBERS we can write: result = a + b; Both 'a' and 'b' are variables. They are symbolic representations of any numbers. For example, the variable 'a' could contain the number 5 and the variable 'b' could contain the number 10. During execution of the program, the statement "a + b" is replaced by the Actual Values "5 + 10" and the result becomes 15. The beauty (and responsibility) of variables is that the symbolic operation should be true for any values. Another example, if we want to find out how many centimeters tall a person is, we could use the following formula: height in centimeters = height in inches * 2.54. This formula is always true. It doesn't matter if its Joe's height in inches or Jane's height in inches. The formula works regardless. In computer terminology we would use: Variable actionsThere are only a few things you can do with a variable:
Below are some examples of how to use variables: Matlab C, Java ActionScript There are 6 properties associated with a variable. The first three are very important as you start to program. The last three are important as you advance and improve your skills (and the complexity of the programs you are creating). Memorize These!
Clarification of Properties
Legal Variable Names
Good Variable NamesGood variable names tell you, your teammates, (and your TA) what information is "stored" inside that variable. They should make sense to a non computer programmer. For example: The Name _vs_ the contained informationThe Name of the variable is not the information! The name is a title of the envelope/bucket, the information is contained in the envelope/bucket. The variable can contain different pieces of information at different times. The information in the variable should be easily manipulated:
|