🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #2554

Re: Report on defect in M2 vs C (Was Modula-2, Modula-3, C or C++)

#2554
From: Farshad Nayeri
Date: Thu, 28 Sep 1995 13:38
105 lines
6172 bytes
In article <Pine.SUN.3.91.950927225244.5434B-100000@lagrange.uwaterloo.ca> Viet-Trung Luu <vluu@lagrange.uwaterloo.ca> writes:

> I don't know that Modula-3's code looks like what it's supposed to do 
> anymore than C code does. What *I* like about C is that once you've 
> learned the language, you can read/write/understand code quite quickly.

I disagree.

My experience is as follows: programmers can learn C pretty quickly
(after a few core dumps.) And you they read and write their own code
quite quickly (except for frequent visits to the debugger.) But
*understanding* code could be quite hard even for trivial programs
written by others depending on the others' programming habits.

> That said, some of C's "features" (?!?) must be at least partially 
> eliminated in a more modern language. Pointer arithmetic is nice and 
> elegant, but unfortunately does not lend itself to the detection of 
> boundary (in arrays) violations or garbage collection. Of course, garbage 
> collection is a *must* for any modern language (C++ fails badly in that 
> regard).

I have to disagree again. Unsafe features are important in a "systems"
programming language, but I agree that even when present they should
be constrained. Otherwise, how can people write garbage collectors? Or
network device drivers? Or interface with some legacy system? What I
think is needed is to *control* the extent which unsafe code affects
safety. There will always be need for mapping data structures to
memory or pointer arithmetic in some code. What you want to do is to
discourage programmers to use unsafe methods unless they really have
to, and if they do, let them do it without making your whole program
unsafe. Note that (a) Modula-3 provides precisely this and (b) C/C++
provide the oppposite (where unsafe operations are the default and
programmers work hard to use safe practices).

> Also, what about the limitations of Modula-3 (virtual -- i.e.,
> late-bound -- methods only)?

In Modula-3 you can have stand-alone non-member procedures as part of
your interface. When efficiency is an issue, you can use procedures or
procedure pointers, and records and record pointers (just like in C,
except with a choice of garbage collection) instead of objects. You
lose some OO power, but I have found that I seldom need to turn to
this approach.

On the other hand, Amer Diwan (diwan@cs.umass.edu) is working toward
an optimizer for Modula-3 which will fold normal Modula-3 code (with
all late-bind methods) into appropriate non-virtual calls when it
makes sense (through flow analysis of your code and finding out things
at compile-time). This means you may get the same efficiency but also
keep the programming model *a lot* simpler.

I think, an essential and difficult part of a good design is deciding
when to leave things out. I feel that Modula-3 designers did a good
job of making sure to stop their desire to include as many features as
they would have liked to include (see last chapter of "Systems
Programming with Modula-3" for more detail). This is why the Modula-3
language spec is about 50 pages, an order of magnitude smaller than
languages with similar programming "power" like C++ and Ada. This is
also partially why the M3 language spec is the true measure of "what's
in the language" and not a particular "reference" implementation, as
is the case for many other languages

Note that, K&R also left things out of C that were considered
essential by others.  This resulted in simplicity and practicality of
C's design which to this day remains one of C's virtues.
(Surprisingly, C's successors have not followed this tradition too
closely.)

> Note: Some actually need power and flex. That's why C (or its variations) 
> is the language of choice for systems programming. However, when building 
> applications... such power (e.g., "I can point that pointer to 
> anywhere!") is unnecessary and troublesome.

Indeed Modula-3 will give you the power and flex (pointer arithmetic,
unsafe casting) when you _really_ want it, but the default choice and
the better one for most programs is to program in SAFE modules where
you can't use pointer arithmetic, arbitrary casting, etc., to shoot
yourself in your foot.

I think the ability of a language to give you "power and flex" has
very little to do with its syntax.

> what I'm saying is that
> it should be possible to have a good, robust language that does big
> projects well without being too verbose. Modula-3 isn't bad -- don't
> get me wrong.  My criticism of Modula-3 is probably 50% personal
> preference (at least 50%, rather). On the other hand, you could
> always go with Ada...

If by "verbosity" you are refering to the Modula-3 syntax, then I
suggest using a C-style pre-processor. You will realize that you won't
be doing a lot of ++'s, but I think you will gain in semantics.  In
doing so you may find that Modula-3 is quite concise in terms of
"semantic verbosity".

I said more than I wanted.

-- Farshad
-- 
Farshad Nayeri
nayeri@gte.com

  ``Obviously, in each of these cases design decisions have been made,
    but unfortunately they were wrong.'' --Victor Papanek, 
                                           Design for the Real World
Technical Details
Message-ID: <NAYERI.95Sep28093827@tahoe.gte.com>
Path: arc1-ca.pugleaf.net!news2.near.net!ceylon!news
References: <438nkr$bd@classic.eng.octel.com> <4395o4$3mv2@news-s01.ny.us.ibm.net> <DAGENAIS.95Sep22100113@gutrune.vlsi.polymtl.ca> <DFI1rr.LyC@undergrad.math.uwaterloo.ca> <Pine.SUN.3.91.950926031537.27808B-100000@napier.uwaterloo.ca> <VIXIE.95Sep26092506@wisdom.vix.com> <Pine.SUN.3.91.950927225244.5434B-100000@lagrange.uwaterloo.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news2.near.net!ceylon!news
From: nayeri@gte.com (Farshad Nayeri)
Newsgroups: comp.lang.modula2,comp.lang.modula3,comp.lang.c,comp.lang.c++,comp.lang.ada
Subject: Re: Report on defect in M2 vs C (Was Modula-2, Modula-3, C or C++)
Date: 28 Sep 1995 13:38:27 GMT
Organization: GTE Laboratories, Waltham, Massachusetts, USA
Distribution: world
Message-ID: <NAYERI.95Sep28093827@tahoe.gte.com>
References: <438nkr$bd@classic.eng.octel.com> <4395o4$3mv2@news-s01.ny.us.ibm.net>
 <DAGENAIS.95Sep22100113@gutrune.vlsi.polymtl.ca>
 <DFI1rr.LyC@undergrad.math.uwaterloo.ca>
 <Pine.SUN.3.91.950926031537.27808B-100000@napier.uwaterloo.ca>
 <VIXIE.95Sep26092506@wisdom.vix.com>
 <Pine.SUN.3.91.950927225244.5434B-100000@lagrange.uwaterloo.ca>
NNTP-Posting-Host: tahoe.gte.com
In-reply-to: Viet-Trung Luu's message of Thu, 28 Sep 1995 03:12:17 GMT