Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!unizh.UUCP!nagler%olsen From: nagler%olsen@unizh.UUCP (Robert Nagler) Newsgroups: comp.lang.modula2 Subject: Re: C vs. M2 Message-ID: <8808150855.AA04539@klaus.olsen.uucp> Date: 15 Aug 88 08:55:51 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Info-Modula2 Distribution ListOrganization: The Internet Lines: 72 In reply to: Steve Losen scl@virginia.edu > Bitwise operators & (and), | (or), ^ (xor), ~ (complement) Modula-2 has types called SET and BITSET. The operations of set inclusion, exclusion, subtraction, union, intersection, etc. are supported. For example, in order to do set subtraction in C you must: x = y & ~z; In M2, this statement is: x = y - z; > Shift operators >> (right shift) << (left shift). In the old days, one used to use / and * to get these operations. Well, you know, this still works. I realize this is a bit archaic, but I rarely have the need for these operations if I have proper set arithmetic. For example, the following is quite common in C: x &= ~( 1 << 5 ); In M2, this is: EXCL( x, 5 ); > 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...). > 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? > Treatment of assignment (=) as an expression, eg, x = (y = 10) + 1; is > equivalent to y = 10; x = 10 + 1; How often do you use this stuff? BTW, you left out such fancy things as: if ( a = x, b = y ) do_it; if ( a == ( b = c ) ) foo_bar; Oh yes, M2 doesn't allow underscores, but it is case sensitive. > 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. > Guaranteed left to right short circuit evaluation of logical expressions Have you ever used M2? Most of the expression semantics are identical to that of C. You can't really compare M2 and C. They are two different beasts. Modula-2 is a system programming language for writing portable modular software. C is a system programming language for writing device drivers and small utilities such as awk, grep, ls, etc. If you have ever tried to maintain a large system written in C, you understand what I mean. Granted that C allows you to program "efficiently", but then you might ask the question: if C is so efficient, why do most people write functions like swab, bcopy, bcmp, printf, etc. in assembler? It has been my experience that C programs run faster only because of the "register" primitive. However, the fastest C code I have seen ignores this declaration (or rather, uses it as advice). It has also been my experience that the software development process goes much faster in M2 as opposed to C simply because of modules and type checking. Funny how the 90/10 rule applies not just to code, but also to programming languages. Rob 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.