From: malak@grebyn.com (Michael Malak)
Subject: Pascal as road to C (was Re: Newbie Wants Advice on C-Programming)
Organization: Grebyn Timesharing
Date: Mon, 28 Dec 1992 04:57:07 GMT

In article <1992Dec27.031157.27179@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
>In article <1992Dec25.070024.15672@grebyn.com>, malak@grebyn.com (Michael Malak) writes:
>> In article <1hdpluINN1lv@agate.berkeley.edu> faustus@ygdrasil.CS.Berkeley.EDU (Wayne A. Christopher) writes:
>> >In article <1992Dec24.172333.7339@grebyn.com> malak@grebyn.com (Michael Malak) writes:
>
>> >> ...  I feel the following must be learned in order:
>> >>   1) Pascal, with two semesters experience
>
>> >IMHO, Pascal has nothing useful that C doesn't have, except for array
>> >bounds checking.  You you use C++ you can use a vector class that
>> >gives you that.
>
>> Pascal has the following advantages over C:
>>    1) It has structured syntactic blocks for constants, types and
>>       variables.
>
>This is no advantage.
>
>A program is a model: an abstraction expressed in a representation.  The
>Pascal seperation of constant, type, and variable classifies the tools of
>representation; it is irrelevant within a program.  Would you require a
>cook to measure out all the ingredients specified by tablespoons before
>measuring any ingredient specified by cups?

No, but I would require the cook to do the following in order:
    1) Purchase the ingredients
    2) Prepare the courses
    3) Serve the meal

In Pascal, types are derived in part from constants, and variables are
derived from types and constants.  I feel that separating out into
blocks these declarations is a good practice to carry over to C.  Now I
believe you're arguing that it's better to clump related definitions
together, even though some may be constants and others types or
variables, such as:

#define BUFFER_SIZE 10000
char buffer[ BUFFER_SIZE ];

I.e., do not have "constant blocks" and "variable blocks".  There are
strong arguments for both ways, _but_ the Pascal organization is better
than none at all.


>>    3) Most importantly, the good structured programming professors
>>       wouldn't be caught dead teaching C (biggotry in my opinion).
>
>Besides which, people who learn Pascal first seem to take three or four
>times as long to learn how to use C pointers as people who don't learn
>Pascal at all, and Pascal introduces people to some really poor habits.
>
>The classical Pascal expression of a loop-and-a-half cannot be written
>as a while() because Pascal's expression syntax is too weak.  It cannot
>be written as a loop-and-a-half because Pascal doesn't allow a `break'
>from a loop.  What results is a circumlocution involving more code in
>control flow and temporary variable managing than in solving the problem;
>worse, one branch of an  if-then  is related to the circumlocution and
>one to the problem to be solved.  This is a very bad form of incohesion:
>
>	if not X
>		manage the loop
>	else
>		solve the problem
>
>This seems to me as damaging to potential software designers as BASIC
>is claimed to be to potential programmers.

Actually, it's a good use of nested procedures.  In C, we have:

while ( TRUE )  {

           :
    /* pre-check stuff */
           :

    if ( X )
        break;

           :
    /* post-check stuff */
           :
}

In Pascal, we have:

pre_check_stuff();

WHILE NOT X
    BEGIN

               :
        /* post-check stuff */ 
               :

        pre_check_stuff();
    END

where pre_check_stuff() is a nested procedure.  In my opinion, the C
"break" is a bad thing simply because you can have more than one per
loop.  It can also lead to bugs, e.g., in nested loops.  "break" and
"continue", as well as mid-function "return"s are nothing more than
"goto"s in disguise.  Which is not to say that they should never be
used, just that it takes experience to know when to use them.  It's a
prime example of how C gives beginners enough rope to hang themselves.
Someone who's suffered through the strictness of Pascal can appreciate
exactly when to use "break"s, "continue"s, "goto"s, and mid-function
"return"s.