3 ms·
> Compare "for (I=0;I<N;I+=5) {" of C with "for I from 0 to N by 5 do" or "for I in 0:N:5 do" of previous languages. C requires typing a lot of redundant charac
by AnimalMuppet 3y ago
> Compare "for (I=0;I<N;I+=5) {" of C with "for I from 0 to N by 5 do" or "for I in 0:N:5 do" of previous languages. C requires typing a lot of redundant characters in the most frequent cases.
Um, "for (I=0;I<N;I+=5) {" is fewer characters than "for I from 0 to N by 5 do".
- adrian_b 3y ago"for I from 0 to N by 5 do" is the verbose variant, which is typical for a language like PL/I or Algol 68. The syntactically equivalent, but non-verbose, is "for I ∈ 0:N:5 ⟨", which beats easily C.
- jandrese 3y agoDo people have normally keyboards with a ∈ key?
- loup-vaillant 3y agoJust remove the ∈ and ⟨ characters, and make braces mandatory: for i 0:N:5 { // loop body } By the way, the same should have been done with if and while: optional parentheses, mandatory braces: if a == b { // code } while idx < end { // code }
- d-lisp 3y agoIt's possible that parsing a complex condition wrapped by parentheses was found more convenient.
- loup-vaillant 3y agoIt’s not. Not for humans (the extra parenthesis is just useless clutter), and not for machines (I’ve written parsers, both alternatives are as easy to implement).
- AnimalMuppet 3y agoSure. And the observant will note that I didn't say that C was shorter than that version. Even if you replace "∈" with "in", it's still shorter. Still... when did that syntax come out? Was it in Algol 68, or PL/I? It seems a bit unfair to complain about C being verbose if it was shorter than anything else available at the time.
- adrian_b 3y ago"∈" was actually proposed for Alphard, at the same time with C. When later implemented, including in an Algol 68 variant that inspired the UNIX Bourne shell, "∈" was replaced with "in", which could be written with ASCII. Algol 68 could use either keyword pairs, like "do" and "od" (which became "do" and "done" in the UNIX Bourne shell) or, optionally, various kinds of parentheses in their place, for conciseness. The notation "0:N:5" or "0:N", when the step is 1, for arithmetic progressions is ancient. Even Fortran used it, but with the mistake of using comma instead of colon, which introduced a syntactic ambiguity, because comma was also used for other purposes. Using colon started with Algol 60, but that one preferred keywords instead of symbols in the arithmetic progressions used inside "for", so it did not use the notation consistently. Fortran in 1954 or the language of Heinz Rutishauser, in 1951 (the first one with a "for" statement), were already much more concise than C.
- Vvector 3y agoThe most frequent case would be increment by 1, so: for (I=0;I<N;I+=1) versus for I from 0 to N do
- f1shy 3y agoI do not remember the author of the quote: A program is written once and read multiple times. Optimize for reading, not writing. The argument “is more keystrokes” in this context is beyound what i can comprehend.