Pascal vs C, again (was: Pascals Origins)

tan at cae780.UUCP tan at cae780.UUCP
Tue Jul 29 11:26:19 AEST 1986


In article <3130 at utcsri.UUCP>, greg at utcsri.UUCP (Gregory Smith) writes:
> 
> Challenge: given
> 
> var	x: array [1..1000] of integer;
> 
> write a code fragment to find the location of the first 0 in x. The
> condition that no zeroes exist must be distinguished.
> 
> Further rules:
> 	- Standard Jensen & Wirth Pascal ( no break from loop )
> 	- *** x[i] must not be evaluated for i<1 or i>1000 ***
> 	- The search loop must be terminated as soon as a zero is found.
> 
> This is the best I can find:
> 	var i: integer;
> 	...
> 	i :=1 ;
> 	while i<1000 and x[i] <> 0 do
> 		i := i+1;
> 	if x[i] = 0 then writeln('zero at location', i )
> 	else writeln('not found');
> 
> weird,huh? Note that the condition 'x[i]=0' is evaluated twice ( once
> in the negative sense ), which would be unacceptable if we were searching
> an array of records and the test was expensive.
> 
> Nobody can call this a special case... and I don't think my rules are
> unreasonable. The problem is the behaviour of 'and' plus the lack of 'break'.
> 
> -- 
> "You'll need more than a Tylenol if you don't tell me where my father is!"
> 						- The Ice Pirates
> ----------------------------------------------------------------------
> Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg



  I don't like your challenge.  If breaking out of a loop can't be considered
as a language feature for Pascal (although it is an extension to the original
Pascal language construct, it is more than common in these days),  we can't
consider the 'enum' construct as a legal feature for C, and anyone who come
up with a 'challenge' that needs the service of this 'enum' monster would 
have thrash C.  I suggest that broader view be taken into account when one
tries to 'compare' a programming with the other.

  The fully evaluation of conditional expression in Pascal may cause some
problem to some people, but they are not hard to get around.  The argued
'x[i] = 0 got executed twice == expensive' does not hold, since one 
such comparison is peanut compared to, say, 100 such operations.  For the
case of 'extremely complicated' data structure, PLEASE use a flag.

  I have done some 'medium' programs using both languages.  I don't have 
any pro or con on both of them.  I like and hate Pascal that it 'force'
me into a rigid track in programming.  I hate it because it takes me 
shorter time to complete my programs, even worse, it is so readable that
anyone can take over my job at anytime !

  I love and hate C also.  She gives me the luxury to fool around with
whatever possible.  I love her 'cause  I know I have a safe job.  No,
I don't love C that much, once it took me weeks to found out that I 
'accidentally' lost one of my mantissa bit in one of my crazy functions
in the 'greatest' program I have ever written (neat eh?).  Oh ya, you
definately can full Pascal by using variant record, but it is more fun 
doing it in C.

  The beauties of both miss C and Mr Pascal have been globally ad.
Sorry for not including these ad's in this article for I am not an
ad. agent.




   ----------------------------------------------------
   -                                                  -
   -  I speak for myself only.                        -
   -                                                  -
   ----------------------------------------------------



More information about the Comp.lang.c mailing list