Datadictionarytechnote
Datadictionarytechnote
Overview
An interesting thing I have noticed when helping students debug programs is the
naming and use of constants and variables. When there is a problem and a student is
having trouble debugging, this is often the cause – the student doesn’t understand the
purpose of the memory locations he or she has established. The constant or variable has
one name, yet when you look at how it is used in the code, it has a different purpose.
A way to assist you is to require you to use a data dictionary function when you declare
your variables. Below are some examples.
decimal decCoursePointsEarned = 0m, //Course-Total Points Earned
decCoursePointsPossible = 0m, //Course-Total Points Possible
decCourseAverage; //Course Average
Notice the following from the example above:
1. Each variable is given a meaningful name
2. Only one variable is declared per line
3. This C# “sentence” has 3 physical lines, but it is one “sentence”
4. After each variable, there is a comment describing the functionality of the
variable
5. Some variables are initialized and some are not. You MUST initialize variables
that are first “seen” by the computer on the right side of an assignment
statement. These are typically counters and accumulators. If the code first “sees”
the variable on the left, then it need not be initialized. This happens when I
convert an input text box value to something and store it in memory for later
use. In the case of decCourseAverage, that gets created when I do a calculation,
so it is not on the right side of an assignment statement. Remember that
processing is done on the right of the =, and the result is stored in the memory
location named by the left side of the assignment statement.
The last two “lines of code” could be one logical line, with a comma between the
constants, because they have the same data type. See the first example for the format.
Summary
Name your variables and constants with words that describe their functionality. If you
are having problems naming a memory location, it could be that you don’t understand
how you will use that memory location.