Why Do So Many Programmers Use One Character Index Variables

There is a commercial on TV these days where a little girl is helping her mother and grandmother prepare a large turkey for a holiday dinner. The little girl asks the older women why the turkey only has one leg. The other leg has been cut off and the older women explain that this is because the little girl’s great grandmother always did it that way. Then a flashback shows that the reason the leg was originally cut off was because the great grandmother didn’t have a pot that whole hold the turkey unless one leg was cut off first. Her daughter and granddaughter and great granddaughter could probably easy buy a pot large enough. In fact the pots they have now might be large enough. But “because that is the way we have always done it” these women were still cutting off one leg.

I remember Grace Hopper once saying in a talk that if we every said “because that is the way we have always done it” she would appear behind us and haunt us. I can’t hear the phrase without thinking of here over 30 years later. But in a real way that is why so many programmers using index variables of one letter and that the letter is between “i” and “n.” So what’s the story?

For many people back in the day the principal programming language was FORTRAN. Early versions of FORTRAN would let you specific the variable type of a name but the default values for integers were variables that started with the letters “i” through “n.” Also with some systems longer variable names took up more room in memory. And memory at that time was expensive. So to make it easy a lot of people used “i”, “j”, and “k” as their first choice for index variable names. That’s how I learned it.

Those of us who learned FORTRAN as a first language brought that habit with us to other languages. To BASIC, and C, and Java, and even PASCAL. And many many more. Why? “Because that is the way we have always done it” Shame on us. And the people we taught taught the same thing to others. That’s not really good. “index” is such a better variable name. In specific cases there are even more helpful, more descriptive and more useful variable names. For counting loops, for variables to pass to methods and many other places. Generally most of use have gone beyond the one character variable name. The last big sticking point seems to be index/loop variables. It’s probably time we all got past that. At least we should teach better practices to our students.