Sujet : Re: Which code style do you prefer the most?
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 06. Mar 2025, 20:36:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vqctf7$33v5m$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
On 06/03/2025 15:49, Scott Lurndal wrote:
David Brown <david.brown@hesbynett.no> writes:
On 05/03/2025 18:51, Scott Lurndal wrote:
Richard Harnden <richard.nospam@gmail.invalid> writes:
On 05/03/2025 17:09, Janis Papanagnou wrote:
On 05.03.2025 17:40, bart wrote:
[...]
>
>
Seriously, short variable names for common things - i, j, k for loop
counters;
>
So, one might ask _why_ i, j, k instead of a, b, c?
>
Answer: Fortran IMPLICIT INTEGER
>
>
Nonsense.
>
Ask rather why Fortran picked i, j, k for integer-type index variables.
Their use for that function in maths /long/ predates Fortran.
That doesn't mean that C programmers didn't adopt the
use of i,j,k from FORTRAN.
I certainly did not. I use i, j, k in maths, then in BASIC, then in Pascal, then in C. No Fortran in sight.
/Everyone/ uses i, j, k for simple indices, because it is standard in maths and is a convention that works well in just about any programming language. Fortran may have been have been one of the first high-level programming languages, but there is no reason to suppose others copied this convention from it.
And while my knowledge of Fortran is close to negligible, I don't believe you are /required/ to use i, j or k for indices - people use other letters or identifiers for loop counters and indices, just as they do in most languages. The only language I know of where you are forced to use i and j is FORTH.
I'm sure that people who first programmed in Fortran, and then in C, took some of their habits with them. And there are no doubt plenty of features of programming and programming languages that Fortran pioneered, and other languages copied - this is not one of them.