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
Language
Assignment Statement
X <- 5
APL
LET X = 5 or X = 5
BASIC
5 -> X
BETA
X = 5;
C, C++
MOVE 5 TO X
COBOL
X = 5
FORTRAN
X =. 5
J
LISP
(SETQ X 5)
Pascal
X := 5
Visual Basic
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
programming examples.
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
programming.
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.
2.2.1 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
recall.)
 
 
Search JabSto ::




Custom Search