|
Looking at Marc's early work on the commodore 64 raised the following question?
Why do we seem to use i and j for loop variables?
Where did it come from I wonder.
And no I have not tried to google it!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Because there is a little bit of FORTRAN in all of us?
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
And everyone who wrote the early tutorials were probably steeped in FORTRAN conventions.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
And the professors who taught us - or those who taught our professors - have a lot more FORTRAN than us so it's a cycle. Add the fact that i and j are short and as good as any single letter...
DURA LEX, SED LEX
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
I think it comes from Fortran, where, at least originally, the letter defining a variable also defined its type. Any variable starting with I,J,K,L,M, or N represented integers. i & j, being the first of these, just followed through from there.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
The answer is obvious. What should be used instead?
a & b?
o & p?
We aren't barbarians are we? i & j is just being civilized.
I remember wondering about it too but didn't delve deeper than letting that thought pass.
Sometimes I use a name instead if its short and descriptive otherwise I try and comment.
|
|
|
|
|
Mycroft Holmes wrote: Why do we seem to use i and j for loop variables? From FORTRAN. Variables starting with the letters I thru N were implicit integers in FORTRAN, and were therefore used as loop counters by default.
/ravi
|
|
|
|
|
To add to what the others said about FORTRAN default variable types, variable names were limited to 6 characters as well so short variable names were a good idea. It was a convention that "generic loop counters" were I, J, and K (no lower case in those days, either!)
In addition, lines were limited to 80 characters of which the first 6 where for label numbers, used to target lines with GOTO and suchlike flow control; and the seventh was for a "Continuation character" which allowed you to use more than 72 characters in your code statement.
Short names were a good idea in those days!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Short names still are a good idea.
As a general rule, I'll use initials for temporary variables in loops etc and as the scope gets greater increase the size and detail of the name.
veni bibi saltavi
|
|
|
|
|
Especially when you had to put them on punch cards!
|
|
|
|
|
Mycroft Holmes wrote: Why do we seem to use i and j for loop variables?
In the east we traditionally used n and m. And p and q for pointers. It wouldn't surprise me if it was just to be different from the decadent west.
|
|
|
|
|
If you took the Fortran IJKLMN, are the letters in the same order when translated to eastern languages? That may explain why your typically using n/m.
|
|
|
|
|
It might have come from FORTRAN, but "i" was also used for short of "index". When using nested loops the next letter was the most obvious ("j", "k", ...)
For me personally it makes perfect sense in some way. If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable. Also a one letter loop variable in an array indication (some_array[i] ) is easier readable than (some_array[index] ). (though that is perhaps personal taste)
|
|
|
|
|
V. wrote: If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable.
Or you are in QA...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
V. wrote: loop variable in an array indication (some_array[i] ) is easier readable than (some_array[index] ). (though that is perhaps personal taste) It depends if that variable has other meaning / is meant to be stored but yes, I concur.
DURA LEX, SED LEX
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
I was initially going to nod to the FORTRAN crowd, then I thought further back, to linear algebra. Indices in vectors and matrices were traditionally i, j, ...
My 2cents.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
The designers of FORTRAN used I,J,...etc. because FORTRAN was designed for FORmula TRANslation and a lot of the language development came from having to process this linear algebra. So when the Integer variables were defined it was natural to use I and J, etc.
So which came first the chicken or the egg?
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
There is no chicken/egg debate. I'm saying FORTRAN followed the linear algebra usage.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I concur. Tensor algebra is much older than FORTRAN, and they always used i, j, k, l for indices, continuing with m, n, and (rarely) more when needed. Mathematicians are notoriously lazy, so they never waste more than one letter for an index variable.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
For matrices I typically prefer row and column . That's still reasonably short, and can help a lot in the readability of some of the matrix operations. (talking of linear algebra matrices here, but you might apply the same reasoning to database tables, resulting in index names like record and field )
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
If it does the job properly, I have no problem paying for software. On the other hand if it is a little buggy but free, fine again. However I really hate slimy advertising that wastes my time with misleading search results. Either it is paid AND buggy, or reasonably good but costs hundreds of dollars to use after the trial.
If it is a free TRIAL, they could f*!%$g well say so from the start.
And while I'm here, I despise sleazy sites that pollute search results with links to search results on their own site. S**tware informer and the like should be blocked by Google.
There, I feel much better now.
|
|
|
|
|
Free Download generally means it costs something.
Free generally means it's freeware.
At least for now.
|
|
|
|
|
I've also seen "Free Installation" a couple of times...
ummm, what?
Sin tack ear lol
Pressing the "Any" key may be continuate
|
|
|
|
|
Agreed wholeheartedly. Which is my[^] freeware is truly free.
BTW, NoNags[^] is a good directory of real freeware. I've been using them since the 90s.
/ravi
|
|
|
|