There are many languages for computer programming. I know only some of those languages that are often called instruction-based or procedure-oriented. These are essentially the same as machine instructions of Von-Neumann-type computers which are interpreted and executed one by one by the machine. But the style has become more readable to human beings, where the "jump" or "go to" instructions in machine languages are mostly replaced by structures for conditional executions and loops.
I think that the relatively recent development of instruction-based programming language has two distinct directions.
One is improvements based on the desire to make huge software run safely. Huge software is made by participation of many people, and often by using library programs already written by someone else. Even if a single person write the whole, he/she would not remember details of some part when writing another part. In such situations, it is recommended to take such a programming style where the information exchanged at the interface between the parts are described clearly, but the information used only within each part will never affect other parts. This style is often called "modularized" style.
Beside modularization, there are some more cautions for making programs
safer.
One of them is that "all variables should be declared before used".
In some languages (such as Pascal), the grammar requires all variables
to be declared.
In some languages there is room for choice.
For example, in Fortran, variables need not be declared,
and then names beginning with I
, J
, K
, L
, M
or N
are assumed as integers
and other names are assumed as "real" (actually floating-point) numbers.
The merit of declaration is evident when human beings make mistakes.
If one misspell a reserved word of a programming language, it will probably
detected by the compiler.
But if one misspell a name of variable, and if it appears as if another
valid variable, it is difficult to automatically detect it.
If all variables must be declared, this kind of mistake will be detected
unless that is a mistake between names of two declared variables.
Most of Fortran compilers accept "IMPLICIT NONE
" statement that
necessitates declaration of variables.
In the C language, declaration of variables are mandatory,
but declaration of types of variables in the argument list of a function
is not mandatory for many compilers.
But the declaration is recommended by most of recent textbooks.
This kind of safety consideration is really precious when writing a considerably long programs. But they are just cumbersome when doing works where a very short program is sufficient. The situation is like a programmer's proverb, "no code, no bug", though actually we need to write some code. When all the executable statements can be seen at a glance, adding declaration statements and making the code cover multiple pages will decrease maintainability and thus probably decrease safety of the code. It is better to use a programming language that is designed for short programs that does not require full declaration.
One typical example for programming language for short programs is Basic. Because it was originally developed for environments with very limited memory capacity, declaration of variables was not mandatory, and structures for modularization were not developed. Though it is possible to write large software with Basic, I do not recommend it, because unsafe codes are not prohibited by the language.
Awk is another example of programming language for short programs only. Programs written in Awk is not modularized: Variables in functions are shared with the main program. Therefore, I think that the appropriate size for an Awk program is at most 100 lines.
While Basic was designed as a general-purpose language,
Awk was designed for "filter"-type application,
in which the program reads the standard input line-by-line
and writes the result of processing to the standard output.
A loop structure that repeats as long as the input exists is built in.
If this mechanism can be utilized, programs can be short, so the
language is the most useful.
(It is possible, however, to write any procedure in Awk
by using the "BEGIN
" part only,
admittedly an awkward way to use Awk.)
Perl and Ruby are general-purpose languages which have a little more modular structure than Awk, but I think they are still languages for shorter programs.
[To the index page of "an awkward awker"] [To the entrance page of K. Masuda in English]