Talk:Comparison of ALGOL 68 and C++

Isn't this discussion missing about a zillion C++ features..? —Preceding unsigned comment added by 140.211.173.16 (talk) 22:11, 13 May 2010 (UTC)

":="
The phrase ":= - assignment operation symbol (to avoid confusion with equal sign)" sounds a bit confusing: Does it mean specifically that c++ hasn't that symbol, or does it mean that c++ has no distinction between comparison- ("==") and assignment-operator ("=")? Phresnel (talk) 14:32, 12 January 2009 (UTC)

There are several different scenarios that come into play: C and C++ both have the irony that the "=" operator uses the "equals" character, but the usage is neither symmetric nor commutative as it is actually a right to left assignment. And where an actual equality comparison is required (in C++ and C) one is required to use the "==" operator.

C descended from ALGOL 68 and BCPL, neither had "==". And both used ":=" for assignment, so I am not sure why C broke the equality.
 * http://www.lysator.liu.se/c/clive-on-bcpl.html

To quote Dennis Ritchie (April 1993). "The Development of the C Language" "Other fiddles in the transition from BCPL to B were introduced as a matter of taste, and some remain controversial, for example the decision to use the single character = for assignment instead of :=. Similarly, B uses /* */ to enclose comments, where BCPL uses //, to ignore text up to the end of the line. The legacy of PL/I is evident here."
 * http://cm.bell-labs.com/cm/cs/who/dmr/chist.pdf

Also note that initially "proto C" used PL/I type declarations, but when Bourne arrived at AT&T this was changed to ALGOL 68 type declarations including the void type.

NevilleDNZ (talk)

Yes, I know. What I am confused about is that the phrase sounds very much like "C (and relatives) doesn't use different symbols for the assignment- and equality-operation", but which is clearly not the case. And "One is required to ..." sounds like personal opinion. I personally, as a Programmer of C and C++ (and PHP, C#, ...) think it is more clumsy to use := as the assignment operator (especially in an imperative language where assignment is one of the most common operations), because both on an english as well as on a german keyboard it is very slow to type that combination (compared to other operators).

I have had exactly that experience of clumsy- and slowness when I was a Delphi programmer for some years a while back. Hence, I personally think one is more "required" to type := than a single =.

Phresnel (talk) 06:48, 13 January 2009 (UTC)

re: "clumsy- and slowness" of ":=", here is an "anonymous quote" from "COMPILER CONSTRUCTION" - W. M. McKeeman: "If PL/I is the Fatal Disease, then perhaps Algol-68 is Capital Punishment". - An Anonymous Compiler Writer Consider ALGOL 68's: FOR i FROM j BY k TO l WHILE m < n DO INT o:=p; print(q) OD Versus C's: for(int i=j; i<=l; i+=k){ if(!m<n)break; int o=p; printf("%d",q); } What is not obvious that in ALGOL 68 the programmer had to go into or out of SHIFT-LOCK a grand total of 14 times. Effectively making this example line 14 key presses longer to type. If your keyboard has a CAPS-LOCK (eg a Selectrics keyboard, or an IBM 3270) then this drops to only 7 extra key presses.

Alternatively - as in the actual ALGOL 68 spec - the reserved word's can be in a bold typeface, while this isn't CAPITAL punishment as such, it still makes for extra typing. eg: for i from j by k to l while m < n do int o:=p; print(q) od

BTW: you can download the ALGOL 68G Interpretor from http://sourceforge.net/project/showfiles.php?group_id=114223 And if you are feeling a bit retro, then add a code sample to http://rosettacode.org/wiki/Category:ALGOL_68 - there are already 100+ samples there. This is a novel way to compare ALGOL 68 with C++. NevilleDNZ (talk)

Heh, that anonymous quote is funny, I didn't know about it, but am I also interested in Compiler Construction in my spare time.

for(int i=j; i<=l; i+=k){ if(!m<n)break; int o=p; printf("%d",q); }

This code sounds rather artficial: m and n don't change (I assume they are not volatile), so why move them inside the for loop? Plus i is a loop-local variable, which means no code after the loop can depend on it. As we are in C and not in C++, the following is semantically equivalent.

if(mi;i+=k){int o=p;printf("%d",q);} v.s. FOR i FROM j BY k TO l WHILE m < n DO INT o:=p; print(q) OD

I don't know ALGOL 68, but I try to minimize it (correct me if I am wrong):

if(mi;i+=k){int o=p;printf("%d",q);} v.s. FOR i FROM j BY k TO l WHILE m<n DO INT o:=p;print(q)OD


 * White space is mostly ignored by ALGOL 68, so you could do this:

v.s. FORiFROMjBYkTOlWHILEm<nDO INTo:=p;print(q)OD
 * At least the compiler would know what to do... NevilleDNZ (talk)

Don't want to make this a flame :D. The reason why I find := clumsy is the reachability without breaking fingers ":": lowest row on keyboard, "=": uppermost row, then, both are nearly at the same column.

I will have a look at those examples, thanks!

- - Phresnel (talk) 15:25, 14 January 2009 (UTC)

Oddly enough, Unicode has some related characters: ≔ 0x2254 8788 COLON EQUALS ≕ 0x2255 8789 EQUALS COLON I guess if I puzzled long enough I'd figure out where ≔ and ≕ came from. I seem to recall that ALGOL W punch cards had a ≔ character. A human would have to look long and hard to find a keyboard that supported this character.

BTW: the "artficial" code: for(int i=j; i<=l; i+=k){ if(!m<n)break; int o=p; printf("%d",q); } Was cut and paste directly from the Unix SysVr5 kernel. (not ☺)

NevilleDNZ (talk) 11:13, 4 February 2009 (UTC)
 * Prof. Koster told us that the  is meant to be an approximation of a left arrow for keyboards without one. Rp (talk) 14:35, 11 May 2012 (UTC)