MS.COM Operations Tools Team WebLog

Hey - What does this button do?

Amateur Hour

We all develop habits.  Some habits are good, some are very bad. Some are easily broken, others require extensive deprogramming.  Our work habits are no different.

 

When I first started in the business I lived in Sillycone Valley and took jobs as a contractor at companies with Unix systems as a means to survive while attending classes.  Most of these contracts entailed simple shell script maintenance.  One of the things I learned, aside from a healthy loathing of the Unix administrators of the day, was that coding habits die hard.

 

Most of us in the IT world are familiar with the infamous “i”.  The ubiquitous variable used in billions of lines of code all over the world to signify a simple numeric variable.  Now, there is nothing intrinsically wrong with using “i” as a variable name, after all it can stand for integer, the type of value it represents.  But what happens when you need more than one integer variable?  Most just increment the alphabet and use the letter “j”, others just pick something, such as “x”.  Again, there is nothing inherently wrong with this system as long as the scope is limited to such things as for loops and whatnot, then it is at least moderately decipherable.

 

But in those early days of shell and C programming that simple little “i” had quickly degenerated into the bubonic plague.  This benign little vowel occurred dozens of times, in random places throughout every file.  And it was joined by a random conglomeration of other vowels and consonants, each representing some value, be it a character or an integer.  And of course there was my personal favorite, adding more “i’s” to create a new integer variable such as “ii” and “iii”.

 

And thus my own coding habits were set.  Over the years I have learned to accept others for their coding habits, such as those above, but I cannot abide in them myself.  Invariably this has led to what I call “Amateur Hour”.  You see, that is what my code looks like and has been ridiculed as throughout my career.  Everything is heavily commented to the point of redundant insanity, every variable is appropriately named and every line of code is spaced and aligned for readability.  I don’t cram three lines of code into one just because it can be done (unless if makes better code, which it often does not).  In fact, the most generic variable name I use is “iCounter” and only within the scope of a for loop.

 

In truth my code really does look like a ten year old has written it and I’m ok with that because while it may be publicly reviled and derided by more proficient developers, no one has ever complained that my code is difficult to read, follow or understand.

 

Will

Published Wednesday, October 06, 2004 10:58 AM by mscomts

Comments

 

Markus said:

If there are others that are deriding you for being obsessive about the quality of your code, you can come and work for me.
October 6, 2004 1:01 PM
 

Simon Cooke [exMSFT] said:

Reasons for using i, j, k:

These are mathematical index variables. Typically you'll see them used in matrices. i indicates the row, j the column, and k? Well, you get the idea.

Reasons for using x, y, z:

These are used when you're iterating over space - x indicates going across a row of pixels / space, and y indicates going vertically down that row of pixels / space. z, of course, goes into the page.

The only other version I've seen is l,m,n - used on the Sinclair Spectrum, because hitting the L key the first time gives you the token for the BASIC FOR command, whereas hitting it the second time gives you L - which is handy as you can rationalize it as "loop variable".

Using i, ii, iii is, however, incorrigible and encourages errors - any repeated single-letter name is going to give you trouble, as you can easily misread it.

Using i, ii, iii, iv, v, vi, vii, viii, ix, x, however, will lead to you being cudgeled to death by a software engineer holding a sundial.
October 6, 2004 3:35 PM
 

Scott said:

Markus -

As Will's manager, I can say that he works for me BECAUSE of this obsessivenss :-) If you work in Operations long enough, you've had more than your share of 2am phone calls where you have to start reading through code. When it's heavily commented and easily read, I spend a lot less time decyphering and a lot more time sleeping!
October 6, 2004 3:43 PM
 

Eric Newton said:

hah that was a good one Simon... LOL
October 26, 2004 12:33 PM
 

MS COM Operations Tools Team WebLog Amateur Hour | Paid Surveys said:

May 29, 2009 9:05 PM
New Comments to this post are disabled

This Blog

Syndication

Tags

No tags have been created or used yet.

News

All opinions posted here are those of the author(s) and are in no way intended to represent the opinions of our employer. This is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker