I’ve never been a first-class programmer; I learn only as much as necessary to get by. There’s just too much programming technology out there and you could spend your entire life learning cool new technologies and never actually getting anything done — and in fact, there are plenty of programmers who live that way.
So no, you really don’t want to read my code. The commenting explanations are skeletal and the structure is pedestrian. Nevertheless, I’ve picked up a few techniques over the years that might be of some utility to others.
The first one was created by a famous programmer at Microsoft (he’s so famous that I cannot recall his name). He used a standard set of single-letter prefixes on all his variable names to indicate their types. Here is my own rendition of his system:
iVariable: an integer
fVariable: a float
bVariable: a boolean (the Java prefix “is” — as in “isAlreadyTaken” — works better)
pVariable: a pointer
hVariable: a handle
cVariable: a count, such as “how many elements are in this array”
sVariable: a string
I also use the standard sequence of variable names i, j, k… for indices in loops. For you young-uns, we use those because, back in the days when we used punched cards, the FORTRAN language had a simple system for differentiating integers from floats. Variables beginning with the letters i through n were integers, and everything else were floats.
I’ll never outgrow my obsolete proclivities for saving memory and execution time in my code. Just for giggles, here are a few useless tricks:
When searching an array of values for a particular item, the crude way is to simply use a FOR-loop and mark the one that matches the specification. However, you can save time by using a WHILE loop, like so:
boolean bGotcha = false;
float fBestValue = -1000f;
integer iBestIndex = -1;
Integer i = 0;
while ((!bGotcha) & (i < cItems)) {
float fTestValue = an evaluation function;
if (fTestValue > fBestValue) {
bGotcha = true;
}
}