torek@elf.ee.lbl.gov (Chris Torek) (04/23/91)
I have no idea what this was doing in comp.object, nor why followups were redirected there. It is only slightly applicable to comp.lang.misc (its other original newsgroup), but that is the one I retained. Anyway: >>2) What? *as usual*, written with two-character "identifiers"? >> After nearly 10 years of C programming, and looking at millions >> of lines of others C code, I have *never* seen *anyone* that >> used *as usual* 2 char identifiers for variable names. > In article <jls.672366979@rutabaga> jls@rutabaga.Rational.COM (Jim Showalter) complains in an aside about (paraphrased) `C programmers using `i' as the control variable on `for' loops). I have wondered at times what makes people believe that this is so horrible. Short, near-meaningless names are not good for long-term data, but they *are* good for short-term data. As an example, I pulled the following out of one of the 4BSD kernel source files (I ran `grep "for (i" *.c' to see what turned up; I got 20 lines, out of 8201 lines in *.c, in /sys/sys.newvm/hp300/hp300 [i.e., code you do not have :-) ]). Here is one of the loops: /* * Initialize callouts */ callfree = callout; for (i = 1; i < ncallout; i++) callout[i-1].c_next = &callout[i]; (This loop turns the array `callout', which has size `ncallout', into a linked list of free callout structures.) Now, this could be changed to use, e.g., for (this_callout = 1; this_callout < ncallout; this_callout++) callout[this_callout - 1].c_next = &callout[this_callout]; but as far as I can tell, this just makes it worse. What we want to express, but cannot because C does not offer such a construct, is: for (all callouts except number 0, in any order) set the previous callout's `c_next' to point to this callout. Since all the callouts are independent of one another, the loop could be run in parallel or backwards or whatever, but we have to choose some index or pointer and some direction and work with that. What does it gain us to decry: `this is the callout we are working on now'? The underlying algorithm is independent of that---all we want to know is that, by the time we are done, the array has been threaded into a list headed by `callfree'. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov