Information Technology Reference
In-Depth Information
12. Programming standards
Before proceeding, it's time for a test. It's actually an exercise to challenge your
brain. The problem is this. We have a balance scale and 8 pills that are all the same color.
One of the pills is poison and the others are plain aspirin. The poison pill weighs slightly
more than the others and can only be discerned by using the scale. How do you positively
determine which is the bad pill in exactly two weighings? A weighing is defined as
loading a set number of pills on each side of the scale and making a determination. Think
about it and I will reveal the answer at the end of the next chapter.
As I have pointed out, we have certain rules in our P language. These have to do
with keywords and their meaning, the way we define variables and use them and how we
put together keywords and variables to form meaningful statements to the computer.
From the sample programs you will note that I indented certain lines but that was not
really necessary. For example the statements
if acct-status = 0
go to read-account
else
go to end-program
end-if
could just as well have been written as
if acct-status = 0
go to read-account
else
go to end-program
end-if
and the program would have functioned properly just as with the first set of lines. The
indentation is done for readability, so that someone looking at the program can more
easily follow the logic of the program. I also mentioned that instead of calling the variable
last-name
for the name of the person corresponding to the account we could just as well have used
the variable
x .
It's just that the latter would give us no clue as to what it represents without further
digging into the program. The variable
last-name
is more meaningful.
Earlier I mentioned that one of the first languages I studied in graduate school was
APL. In that language you could eventually reduce any program to a single continuous
statement. It might extend over one line but one statement would do. If you wrote the
program as a series of statements and thoroughly tested it so that you were completely
Search WWH ::




Custom Search