Microsoft Office Tutorials and References
In Depth Information
Table 2-2. Assignment in Various Languages
Programming languages vary quite a bit in their syntax. Some languages are much easier to read
than others (as are spoken languages). As a very simple example, Table 2-2 shows some ways that
different programming languages assign a value (in this case, 5) to a variable named X. Notice the
variation even in this simple task.
Table 2- . Assignment in Various Languages 2
X <- 5
LET X = 5 or X = 5
5 -> X
X = 5;
MOVE 5 TO X
X = 5
X =. 5
(SETQ X 5)
X := 5
X = 5
If you're interested in how Visual Basic compares with some of the other major programming
languages, Appendix F contains a short description of several languages, along with some
2.2 Programming Style
The issue of what constitutes good programming style is, of course, subjective, just as is the issue
of what constitutes good writing style. Probably the best way to learn good programming style is
to learn by example and to always keep the issue somewhere in the front of your mind while
This is not the place to enter into a detailed discussion of programming style. However, in my
opinion, the two most important maxims for good programming are:
• When in doubt, favor readability over cleverness or elegance.
• Fill your programs with lots of meaningful comments.
Let us take the second point first. It is not possible to overestimate the importance of adding
meaningful comments to your programs—at least any program with more than a few lines.
The problem is this: good programs are generally used many times during a reasonably long
lifetime, which may be measured in months or even years. Inevitably, a programmer will want to
return to his or her code to make changes (such as adding additional features) or to fix bugs.
However, despite all efforts, programming languages are not as easy to read as spoken languages.
It is just inevitable that a programmer will not understand (or perhaps not even recognize!) code
that was written several months or years earlier, and must rely on carefully written comments to
help reacquaint himself with the code. (This has happened to me more times that I would care to