<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx</link><description>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</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9249926</link><pubDate>Tue, 23 Dec 2008 15:48:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9249926</guid><dc:creator>Robert MacLean</dc:creator><description>&lt;p&gt;I switched to calling the variable counter a few years back, after a static analysis tool (I think it could've been FXCop) marked i as a bad variable name.&lt;/p&gt;
&lt;p&gt;Maybe the use of good static analysis tools should be introduced into schools more heavily to help show learners even through it works, it may not be the best way?&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9249943</link><pubDate>Tue, 23 Dec 2008 16:01:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9249943</guid><dc:creator>Jamie Thomson</dc:creator><description>&lt;p&gt;This strikes me as a good thing rather than a bad thing. We preach about reusing code all the time, why not reuse coding conventions as well?&lt;/p&gt;
&lt;p&gt;In other words, if everybody (well, most-everybody) is doing the same thing....let's keep doing it.&lt;/p&gt;
&lt;p&gt;Just my opinion.&lt;/p&gt;
&lt;p&gt;-Jamie&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9250246</link><pubDate>Tue, 23 Dec 2008 18:32:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9250246</guid><dc:creator>jtenos</dc:creator><description>&lt;p&gt;I agree with previous commenter Jamie.&lt;/p&gt;
&lt;p&gt;Just because our current reasoning isn't the same as it was 30 years ago doesn't mean we should stop doing it. &amp;nbsp;I like this convention when dealing with short loops - if I ever see &amp;quot;i&amp;quot;, then I know I'm in a for loop, and if I see &amp;quot;j&amp;quot;, then I know I'm nested inside another for loop where &amp;quot;i&amp;quot; is the &amp;quot;parent&amp;quot; loop.&lt;/p&gt;
&lt;p&gt;If we didn't use &amp;quot;i&amp;quot;, &amp;quot;j&amp;quot;, etc., then there probably would be no convention - some people would use &amp;quot;counter&amp;quot;, maybe &amp;quot;counter1&amp;quot; and &amp;quot;counter2&amp;quot; or &amp;quot;outerIndexer&amp;quot; and &amp;quot;innerIndexer&amp;quot; or other crazy stuff like that.&lt;/p&gt;
&lt;p&gt;But at the same time, I would absolutely not use one-character variables for anything other than an indexer, ever. &amp;nbsp;I'd never have a string named s, or a float named f, in an actual application.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9250505</link><pubDate>Tue, 23 Dec 2008 20:57:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9250505</guid><dc:creator>gflint</dc:creator><description>&lt;p&gt;I have to agree with jtenos. &amp;nbsp;I like the i,j,k thing. &amp;nbsp;I think programmers are inherently lazy (after all, they sit on their ass in front of a computer all day, how much lazier can you be) and having some little conventions like this allow me to be even lazier. &amp;nbsp;As soon as the i,j,k become confusing they are toast.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9250533</link><pubDate>Tue, 23 Dec 2008 21:12:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9250533</guid><dc:creator>Kevin Daly</dc:creator><description>&lt;p&gt;I used to use meaningful names for loop variables but abandoned them.&lt;/p&gt;
&lt;p&gt;I got sick of &amp;quot;so what will I call the next one?&amp;quot; - it just wasn't something useful to spend my time on.&lt;/p&gt;
&lt;p&gt;the &amp;quot;i,j,k&amp;quot; convention is known and understood across a range of languages, and because of the context it is always clear that these are loop variables. If there is any doubt about the purpose of the loop, write a comment.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9250595</link><pubDate>Tue, 23 Dec 2008 21:47:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9250595</guid><dc:creator>C. Watford</dc:creator><description>&lt;p&gt;How about the advice:&lt;/p&gt;
&lt;p&gt;&amp;quot;i, j, k&amp;quot; are your best choice for loop indexes except for when they are not.&lt;/p&gt;
&lt;p&gt;Personally, I use &amp;quot;ii, jj, kk&amp;quot; and never have one letter variables. Regardless, as loop indexes one or two letter variables do not noticeably impact readability or maintainability of code.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9251039</link><pubDate>Wed, 24 Dec 2008 01:28:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9251039</guid><dc:creator>Brons</dc:creator><description>&lt;p&gt;I would have said that it was a habit carried over from math. Take the Captial Sigma notation for a summation, where you write stuff like n over Capital Sigma over i=m, meaning that the index i varies from m to n. Capital Sigma being hard to transcribe in simplel inear algorithmic languages, you transcribe that as FOR I=M TO N or for (i=m, i&amp;lt;n, i++) or whatever, but keep the simple index i.&lt;/p&gt;
&lt;p&gt;No?&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9251070</link><pubDate>Wed, 24 Dec 2008 01:47:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9251070</guid><dc:creator>Dave Briccetti</dc:creator><description>&lt;p&gt;I program mostly in Java these days, and generally follow Sun’s guidelines: &lt;a rel="nofollow" target="_new" href="http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367"&gt;http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html#367&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I like short names for “temporary” variables.&lt;/p&gt;
&lt;p&gt;I find myself becoming much less tolerant lately of “noise” in source code. Consider the following:&lt;/p&gt;
&lt;p&gt;ArticulatedArmMember articulatedArmMember = new ArticulatedArmMember();&lt;/p&gt;
&lt;p&gt;articulatedArmMember.setNumFlanges(10);&lt;/p&gt;
&lt;p&gt;articulatedArmMember.setColor(Color.RED);&lt;/p&gt;
&lt;p&gt;⁝&lt;/p&gt;
&lt;p&gt;I consider all the repetition of “articulatedArmMember” to be noise, and much prefer something like:&lt;/p&gt;
&lt;p&gt;ArticulatedArmMember aam = new ArticulatedArmMember();&lt;/p&gt;
&lt;p&gt;aam.setNumFlanges(10);&lt;/p&gt;
&lt;p&gt;aam.setColor(Color.RED);&lt;/p&gt;
&lt;p&gt;⁝&lt;/p&gt;
&lt;p&gt;But only for local variables where the scope is short. For an instance variable I would use the full name, articulatedArmMember.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9251074</link><pubDate>Wed, 24 Dec 2008 01:49:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9251074</guid><dc:creator>Doug Peterson</dc:creator><description>&lt;p&gt;Since we're admitting date, let's take it one step further. &amp;nbsp;For those of us who cut our teeth on Fortran AND used mark sense cards, it not only made sense, but led to fewer errors when creating the program.&lt;/p&gt;
&lt;p&gt;Of course, that doesn't explain why we didn't change and grow with it but that's my story and I'm sticking to it. &amp;nbsp;i for the first loop; j for the next embed; then k ...&lt;/p&gt;
&lt;p&gt;On the other hand, there's the old adage that if a program was hard to write, it should be equally as hard to modify by others!&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9251108</link><pubDate>Wed, 24 Dec 2008 02:35:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9251108</guid><dc:creator>Name</dc:creator><description>&lt;p&gt;Buy a bigger pot? Yeah, just put it on the credit card. Thinking like yours got us into this whole mess!&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9255798</link><pubDate>Mon, 29 Dec 2008 18:48:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9255798</guid><dc:creator>Rob Miles</dc:creator><description>&lt;p&gt;I've wondered about this before. I tried longer count variables but these got in the way and so I went back to i and j. I tell my classes to use i and j too, since they are quick and easy to use, and they will see this practice in other programs.&lt;/p&gt;
&lt;p&gt;Whilst I can see a point in adding value to the names I don't think the value is worth the hassle. And anyway, why worry? One of my favourite quotes (which programmers should keep in mind) is &amp;quot;A foolish consistency is the hobgoblin of little minds&amp;quot; from Emerson.&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9257350</link><pubDate>Tue, 30 Dec 2008 20:21:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9257350</guid><dc:creator>Clint Rutkas</dc:creator><description>&lt;p&gt;While yes IDEs do make it faster to have longer names, but for looping, i,k,j just make sense. &amp;nbsp;Yes, it was taught to me that way but there is no need IMO to make them any longer if all they are doing is acting as an index. &amp;nbsp;If that index had additional calcuations done on it, that may be a different case.&lt;/p&gt;
&lt;p&gt;Long story short, I agree with @jtenos&lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9293989</link><pubDate>Thu, 08 Jan 2009 08:24:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9293989</guid><dc:creator>Kaan</dc:creator><description>&lt;p&gt;Using counter instead of i, is one of the stupidest things i've read that was not on the dailyWTF. Longer is not better. i is just as unique, and descriptive. If you want to write self documenting code then you might want to chose a long index variable name that describes what is being iterated through. For example for(int rowI = 0; rowI &amp;lt; nRows; rowI++) is usefull if you are iterating through say rows of SQL data. &lt;/p&gt;
&lt;p&gt;Even there it isn't quite necessary. If you make sure to comment the actual statements in the for loop, any programmer worth his salt should be able to look at for(int i=0; i&amp;lt;nRows; i++) and realise that i is the index for rows. &lt;/p&gt;
</description></item><item><title>re: Why Do So Many Programmers Use One Character Index Variables</title><link>http://blogs.msdn.com/alfredth/archive/2008/12/23/why-do-so-many-programmers-use-one-character-index-variables.aspx#9319002</link><pubDate>Wed, 14 Jan 2009 20:03:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9319002</guid><dc:creator>Jim</dc:creator><description>&lt;p&gt;I'll probably continue to use i,j,and k as I learned in 1972 (before Watfor...) because I only do it in short-scoped situations where the meaning is clear to the reader. It saves me typing, conforms to math notation for the most part, and doesn't hurt anything. &lt;/p&gt;
&lt;p&gt;I still catch myself typing &amp;quot;Dimension i&amp;quot; instead of &amp;quot;Dim i&amp;quot;.&lt;/p&gt;
</description></item></channel></rss>