Path: utzoo!utgpu!attcan!uunet!husc6!purdue!decwrl!vixie From: vixie@decwrl.dec.com (Paul Vixie) Newsgroups: comp.lang.modula2 Subject: Re: C vs. M2 Message-ID: <49@volition.dec.com> Date: 15 Aug 88 18:46:54 GMT References: <8808150855.AA04539@klaus.olsen.uucp> Organization: DEC Western Research Lab Lines: 80 # > Pre and post increment/decrement operators (++, --); # INC, DEC are a hack in M2 to satisfy people who think they can out-code # a compiler. (With most M2 compilers, this is understandable...). It's a question of appearance. I can say while (*p++ = *q++) ; But then, does M2 have arithmetic for pointers? Also, INC and DEC are not functions which return the new value -- why not? # > The ? : operator, eg, x = (y < 2 ? 10 : 20) + y; is the same as # > if (y<2) x = 10 + y; else x = 20 + y; # Pardon me, but did you ever program in APL? Another question of appearance. I like: printf("%d block%s\n", i, (i=1)?"":"s"); # > Large assortment of assignment operators (+=, -=, *=, /=, &=, |=, etc) # > eg, x *= 2; is equivalent to x = x * 2; # M2 doesn't go into that sort of thing. Seems like even the most # rudimentary expression optimizer could take care of this problem # lickety-split. Yes, it's true, a good compiler will find the best way no matter how you say it. But again, appearance gets my vote: foo[i]->bar.size += newsize; vs. foo[i]^.bar.count = foo[i]^.bar.count + newsize; I get to say what I mean. Yes, I know about INCR, but this is only one case. # You can't really compare M2 and C. They are two different beasts. I agree. M2 ends up being more elegant, or at least I end up being more elegant when I use it. :-). C lets you do some things more clearly, but the code ends up being a lot more dense per square inch of EMACS windows, and C has things that I sometimes can't help taking advantage of, in spite of the pain I experience later trying to understand what I did. Both languages have their place. # PS. Riddle of the day. How do you do the following in C? # TYPE # RealPtr = POINTER TO REAL; # X = PROCEDURE ( # CARDINAL # ) : RealPtr; # A = ARRAY [ 0 .. 5 ] OF X; # VAR # x : POINTER TO A; # # Ok, skip the CARDINAL parameter, but I'd like to see the rest. Sigh. You're going to love this. Let's skip the CARDINAL parameter, as you suggest, since non-ANSI C doesn't let you specify parameters when you declare a function. typedef real *RealPtr; typedef RealPtr (X)(); typedef X A[6]; /*var*/ A *x; M2 is _much_ clearer. Anybody got an example of something like this that C does more clearly? Something useful would be nice... Calling one of A's functions is fun: (*((*A)[i]))(param1, param2); (I may have too many parens. I always puzzle over this part of C.) -- Paul Vixie Digital Equipment Corporation Work: vixie@dec.com Play: paul@vixie.UUCP Western Research Laboratory uunet!decwrl!vixie uunet!vixie!paul Palo Alto, California, USA +1 415 853 6600 +1 415 864 7013