|
True, true.
But at least it is faster than typing 'rowndx' or (Deity forbid!) 'elementIndex'
A human being should be able to change a diaper, plan an invasion, butcher a hog, navigate a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects! - Lazarus Long
|
|
|
|
|
Single letter loop counters is not just FORTRAN -- C as well.
|
|
|
|
|
But it started in FORTRAN which had implicit typing based on the first letter of the variable name: I to N inclusive were integers, everything else were reals. With no enforced declaration, it became a convention that I, J, K were integer values used in loop guards.
C always had compulsory variable declaration, which made typing by variable name irrelevant - and got rid of a lot of errors: NASA "lost" a probe because someone mistyped a comma.
What they meant to type:
DO 15 I = 1,100 A loop to Label 15, integer I runs between 1 and 100 inclusive.
What was typed:
DO 15 I = 1.100 Because FORTRAN ignored spaces outside strings, this was seen by the compiler as:
DO15I = 1.100
which is a perfectly valid assignment to a brand new variable called DO15I. Since there is no need to declare a variable, the "D" makes it a real variable, and that's completely legal (if rather useless)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: But it started in FORTRAN Very true! However, I expect a lot more folks frequenting this forum picked the naming habit from C rather than FORTRAN.
That would make an interesting poll -- list languages popular before 1990 and get counts of who has done what.
|
|
|
|
|
God is real, unless declared otherwise by an IMPLICIT statement or an explicit declaration.
This joke was well known in the late 1970s. For those who never worked with Fortran:
IMPLICIT COMPLEX (F-H) would make all variables starting with an F, G or H to be of default type COMPLEX. You could explicitly decare REAL GOD, overriding the IMPLICIT, but if you simply referenced GOD with no declaration, GOD would be COMPLEX.
I once spent a full day helping one guy find the cause for his program Fortran behaving in completely crazy ways. I didn't spot it until I single stepped through his program, machine instruction by machine instruction, seing that the compiler referenced two different locations, seemingly selected at random, that should have been a single location. Or ... Searching for the variable name in the source code hit only half of them. In the other half, the letter O was written as the digit 0, and in both the screen and printer fonts the two were almost perfectly identical. Obviously, the coders had used a lot of copy/paste to get that many occurences of 0.
In Fortran, you can declare IMPLICIT NONE (at least from Fortran 77 onwards), forcing you to explicitly declare every variable, as in any other decent programming language. But lots of old Fortran programmers hated having to tell in advance that they were going to need this and that variable; they didn't see the point of explicit declaration, and refused to use IMPLCIT NONE.
Some programmers are that way even anno 2019, praising their favorite language because variables are implicitly declared. (Or that they don't need braces around composite statements. Or use braces rather than BEGIN END. Or int rather than integer, bool rather than boolean / logical. Or... So don't be too harsh with the old Fortran programmers!)
|
|
|
|
|
I am an old FORTRAN programmer! It was the second language they taught us at Uni - the first (Gawd help us) was COBOL which was enough to put quite a few people right off the whole idea...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Not just FORTRAN. We used i, j, and k for loop vars in all my C and C++ classes, too.
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
As I said earlier: The Lounge[^]
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Pardon the repetition. I don't always read every other comment before adding my own. TL;DR syndrome.
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
No problem: I thought of copy'n'paste but couldn't be arsed!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you think 'goto' is evil, try writing an Assembly program without JMP.
|
|
|
|
|
I have never touched Fortran or Cobol and I use the same conventions, I have no idea where I picked it up from as I learnt to code on a commodore 64 and then from a SuperBase manual.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Some early BASIC versions allowed up to 26 numeric variables; i through m (?) were integers, everything else floating point. It's a reflection of the generosity of 26 variables that in practice most of us only ever needed i, j, k as integers; we really were spoiled for choice.
|
|
|
|
|
My first BASIC experience was with 286 variables: A-Z, A0-A9, B0-B9, ... And 26 string variables: A$ to Z$. I never saw a BASIC so tiny that it had only 26 numeric variables - maybe it existed, but I doubt that any real world problems were solved with that compiler .
Also, the first Basic compiler I worked with didn't distinguish between integer and float - that was quite common in the early Basic days. I believe that with the Univac 1100 mainframe series Basic, every variable was born as integer, but as soon as it was assigned a float literal value or the result of a non-integer expression, the type was changed on the fly. (So I think it really was an interpreter, not a compiler system.) No Fortran style implicit type by (first) letter.
|
|
|
|
|
I used the same conventions, I started with Basic and Pascal, then Delphi and VB
|
|
|
|
|
this style works for me. Its hip like texting acronyms now. You could use i d k instead or f y i.
My personal favorite was back when I used VB
Dim g as string... It made my programming style quite revealing.
|
|
|
|
|
j snooze wrote: You could use i d k They would be good for WHILE loops, but not FOR -- because with FOR loops, you do k.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Are you telling that there is an other way to do loops?
(To be honest I never did FORTRAN, but the i,j,k variable names came down to me via C while learning)
"The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018
|
|
|
|
|
A while ago [^].
I never coded in FORTRAN. I suppose it comes (like FORTRAN) from mathematics.
|
|
|
|
|
|
Developers who are content with Textbox1, Textbox2 irk the crap out of me, never mind merely irritate.
"'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself."
—Aleister Crowley
|
|
|
|
|
I also used i,j,k for indices, why does it bother you?
Although someone ask me, once, to use more descriptive name, so I indulged him and refactor my indice to "variableIndiceForArrayIndexFrom0ToListCount" which, granted, is much more descriptive and easy to read!
|
|
|
|
|
well another memory muscle reason for many...
before FORTRAN many learned BASIC (back in the day when a school would have 2 or 3 TRS-80 or similar computers, the first version (Model I with 4k RAM) only had single char variables A..Z. Later the Model II (with the massive 16k) allowed 2 letters AA..ZZ.
anyhoo it was actually in the Programming Guide (probably inspired from FORTRAN) that suggested
I, J, K, L... for "general" integers (in particular FOR loops), (also ref: I for iterator)
S, T, U for general strings.
"Important" variables used A, B, C (effectively the global variables)
suggested sticking to single letters for compatibility with Model I.
Some versions of FORTRAN also had that 2 letter limit.
"That way you could better determine what any variable was for/about."
mock it if you will, but given the naming limitations of the time at least some were already invested enough to come up with some common coding styles.
- Nowadays i, j as iterators/offsets even makes appearances in mathematics,
- when you see "for (i = 0; ..." you already know the intent (unless you or the programmer are idiot(s), and that's even if it's someone else's code.
-- and inasmuch almost makes it better to keep using i, j
... unless you're some sort of purist 'style wanker' who says 'the code may be misunderstood'
..... (and let's face it: such comments are nearly always a reflection of the lack of abilities of the idiot quoting them).
|
|
|
|
|
For general strings I kind of like S T F U. No offence intended, merely humor.
|
|
|
|
|
But of course. The shorter the scope, the shorter the name. The longer the scope, the longer the name.
Waaayyy back in a Pascal class I took in the mid-80s (on a PDP-11), for one assignment I chose to use the number of syllables of nonsense words to indicate the usage of the variables. Try typing "tafimadiddle" many times on a VT-100 (no cut/paste).
|
|
|
|
|