[net.lang.mod2] Modula-2 vs. C

janney@unm-cvax.UUCP (08/07/84)

I doubt if we will get a "long and fruitless debate" over Pascal vs.
Modula-2.  Modula-2 is too clearly an improvement over Pascal.  Even
the "advantages" of Pascal can be considered disadvantages, as they
make the language larger and more difficult to implement.  Let's talk
about a more interesting comparison:  Modula-2 vs. C.  I'll make some
initial comments to get things going.

Advantages of Modula-2

	Clean, consistent support for the notion of data types and data
	structures.  This is probably the biggest advantage.  Type
	declarations are clear and readable even for complicated types,
	whereas even simple declarations in C take some getting used to.
	Arrays and records are passed to procedures in the same way.
	You don't have to worry about how to declare NULL.

	Many aspects of program correctness can be checked by the
	compiler, thus eliminating whole classes of errors.  The
	separation of definition and implementation modules makes
	it easy to do checking across files.  This, and the whole
	concept of modules, should be most valuable in very large
	projects.

Advantages of C

	Unquestionably, the greatest advantage of C is its unification
	of pointers and arrays, and the ability to do address
	arithmetic in a simple and well-defined way.  Properly used,
	this flexibility can greatly simplify many programs.  It
	allows a natural, useful implementation of strings without
	further extension of the language.

	Global data, in particular arrays, can be initialised at load
	time--in Modula-2, all initialization must be done with executable
	code.  This is particularly useful in table-driven software
	like the output of yacc or lex.

	Having a built-in, standard (well, mostly standard) preprocessor
	can be really nice.  It's nice to be able to give a complicated
	expression a symbolic name without incurring the overhead of a
	function call.  On the other hand, file inclusion wouldn't be
	too useful in Modula-2: that's what the modules are for.

	A really nifty for loop, and the ability to break out of any
	kind of loop.

Some differences that are arguable are runtime array bounds checking,
sets vs. explicit bit manipulation, and of course syntax.  I claim that
the "ease of typing" argument is a bogey-man: when I edit a Pascal program,
I have vi set up so that when I type ^B I get begin, ^E end, ^P procedure,
and so on.  This should be possible with any good screen editor.

Hoping to see some more discussion,

Jim Janney
{{ucbvax,gatech}!unmvax, {purdue,lbl-csam,ihnp4!cmcl2}!lanl-a}!unm-cvax!janney

prl@murdu.OZ (Peter Lamb) (08/15/84)

Most things in Modula 2 are safer than C, but I think that
the ADDRESS operator returning POINTER TO WORD, rather than
POINTER TO <object_type> as happens in C
is a bit of a grot. If POINTER TO WORD was what you
*REALLY* wanted, then it can be coerced that way.

The only other aggravation is the persistance of the
ban on string constants of length 1. Why is it that Pascal and
MODULA both fail to provide a syntax for this object?
The problem is that '' and 'ab' are ARRAY OF CHAR, but
'a' is CHAR, ie, trying to use the same syntax for two
very different objects.

rcd@opus.UUCP (Dick Dunn) (08/17/84)

>Re: Modula-2 and Initialization.
>
>A highly optimizing complier could take most of the statements in a
>module's initialization block, and convert them into load time data, as
>opposed to run-time initialization code. I can't remember anything in
>the language definition that would prevent this.

While this is a valid argument for an existing language, it always pains me
to see the following sequence:
	- language design omits a necessary (or commonly useful) feature
	  [case at hand: variable initialization]
	- user is forced to work around lack of the feature [substitute
	  assignment statements]
	- compiler-writer has to figure out the optimization step to
	  recognize the now-disguised feature and implement it [find a
	  certain class of assignments and turn them into load-time
	  initializations]
It's painful because both the user and implementor of the language
recognize a mechanism that the designer has ignored.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
	...Never attribute to malice what can be explained by stupidity.

tower@inmet.UUCP (08/21/84)

Re: Modula-2 and Initialization.

A highly optimizing complier could take most of the statements in a
module's initialization block, and convert them into load time data, as
opposed to run-time initialization code. I can't remember anything in
the language definition that would prevent this.

I don't know of an implementation that does this yet
but it is quite do-able!

-len tower		UUCP:     {ihnp4,harpo}!inmet!tower
 Intermetrics, Inc.	INTERNET: ima!inmet!tower@CCA-UNIX.ARPA
 733 Concord Ave.
 Cambridge, MA  02138	(617) 661-1840
 U.S.A.