Chapter 7: i

 < Day Day Up > 



 Download CD Content

Description

The title of this illness might have you wondering. This is exactly the same response programmers have to poorly named variables. Without a meaningful name, the only way to determine what a variable does is to examine its usage or read its documentation, if any is available. Even worse, if the variable is an undocumented member of a library to which you do not have the source code, the only possibility is through trial and error usage that might never fully reveal what the variable does. Therefore, the name of the illness itself should serve as a simple reminder to always provide meaningful names within the code.

The particular choice of i for the name comes from one of the most common constructs in the C language, the loop iteration:

   for(int i = 0; i < end; ++i) {       // Do something with i...    }

Here the i stands for iteration. Original memory was sparse even for the source code, and in the case of interpreted languages, the source code might have been the program itself. Because of this, and the desire to type less, programmers chose short names that often had only an obscure connection to their meaning or no connection at all. However, despite the abundance of memory available and the tools for writing code faster, this tradition still hangs on in many cases.



 < Day Day Up > 



Preventative Programming Techniques. Avoid and Correct Common Mistakes
Preventative Programming Techniques: Avoid and Correct Common Mistakes (Charles River Media Programming)
ISBN: 1584502576
EAN: 2147483647
Year: 2002
Pages: 121
Authors: Brian Hawkins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net