[net.lang.mod2] Modula-2: some opinions

powell@decwrl.UUCP (10/21/83)

From: Mike Powell <powell>
The following are some brief opinions of mine about Modula-2.
Since the good things are commonly believed, I won't elaborate on them.
I will offer terse explanations of why the bad and questionable things are so.
Note that I do not expect the language to be my dream language.  I just want
a language that looks like we learned something in the 10 years since Pascal.
For a description of Modula-2, see Wirth's book, published by Springer-Verlag.

Good things:
    Most of Pascal's problems have been fixed:
	No more begin/end idiocy; A loop-and-a-half is easy with the LOOP/EXIT;
	Procedure variables;  VAL (like chr for enumerations); Allows multiple
	occurrences of CONST, TYPE, VAR, and PROCEDURE declarations; Some
	forward referencing allowed; ELSE on case;
    Some Pascal things were dumped, and good riddance:
	Untyped set expressions; strange I/O; label declarations and goto's;
    Some new things:
	MODULES AND SEPARATE COMPILATION!  Explicit imports and exports;
	Type coercion; Co-routine mechanism; Open array parameters;

Bad things:
    Keywords and standard identifiers in UPPER CASE;
	Do I really need identifiers such as If, iF, and if, or real, Real,
	ReAl, etc.?  Putting words such as IF in upper case emphasizes them
	visually all out of proportion to their importance.  Case should be
	ignored in language-defined tokens.
    String constants;
	Why allow either 'xxx' or "xxx"?  Simply to allow '"' and "'"?  This
	problem was solved long ago -- either allow doubling of the quote mark,
	or introduce a meta-character.  Also, the one-character-string dilemma
	of (most implementations of) Pascal is retained in Modula-2.  The C
	solution is better, but, since Modula-2 will assign a (multi-character)
	string constant to a character array of larger size, why not do the
	same thing for single-character strings?
    No set-former expressions;
	Since the type is known (specified or assumed) for all set expressions,
	why not allow, as Pascal did, expressions in set-formers? In Pascal,
	expressions caused problems when the set type wasn't known, but
	Modula-2 fixed that.

Questionable things:
    Cardinal data type;
	The cardinal type itself is not bad, but the fact that non-negative
	subranges have cardinal (not integer) as their base type, coupled
	with the fact that cardinals and integers cannot be mixed in
	expressions, means means that i * j, where i : [0..10]; j : [-5..5],
	is illegal.  Cardinal arithmetic is also MORE difficult on many
	machines, rather than easier as is claimed by Wirth.  It would make
	more sense to say that only those subranges with upper bound > MAXINT
	would be of base type cardinal.  Exercise for the unconvinced: write
	a code template for the loops
	    for i := 10 to 0 by -1 do ... end;
	    for i := 10 to 0 by -3 do ... end;
	where i is cardinal (Don't cheat by assuming 10 and 0 are constants).
	What is needed is a positive integer type, which takes on values in
	[0..MAXINT].  This would be used most of the time.  Cardinal would be
	reserved for whole-word unsigned arithmetic and address calculations,
	would not be allowed as a for loop index, and might be more expensive
	to multiply and divide.
    No (reasonable) standard for I/O;
	I guess it is better not to do something than to do it wrong, but it
	will be difficult to have even vaguely portable programs without an
	I/O facility.  It's hard to explain why output, at least, is not
	defined, since Pascal's solution worked well.  In the absence (and even
	presence) of overloaded procedures, the procedure-call-per-item method
	is annoyingly verbose.
    Opaque types;
	Some data abstraction is better than none.  Opaque types work for many
	common cases, so I can't complain about them.  Yet for epsilon more
	mechanism, opaque types could have supported multi-word types.

Summary:
    I give it a B+ (Of course, if Wirth were an undergraduate, he would get
    an A+, but he should be able to do better).

Epilogue/Sequel:
    I have implemented a compiler for the VAX and, although (I think) it abides
    by the rules when you ask it to do so, I have relaxed some restrictions in
    some areas.  More details will be forthcoming.  Meanwhile, I am interested
    in hearing opinions about features of Modula-2, and compilers that may take
    liberties with the language.

						Michael L. Powell
						DEC Western Research Lab
						decvax!decwrl!powell