Efficient coding considered harmful?

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Nov 3 03:36:22 AEST 1988


In article <137 at twwells.uucp> bill at twwells.UUCP (T. William Wells) writes:
>#define HASHSIZE 4              /* A power of two, or else! */

To continue my complaint against using bitwise operators where arithmetic
is called for, let me point out that most reasonable hashing schemes work
best of the hash table size is NOT a power of two.  Now, if you had used
arithmetic instead of bit-diddling throughout your hashing code, most
likely a programmer could change HASHSIZE to some useful number like 113
and that would be all it would take to improve the hashing scheme.  On
the other hand, your code would force him to either use 128 (and obtain
suboptimal performance), or else go through the code and try to put it
back in the shape it should have had from the outset.

Again, this is a case that any decent compiler would have been able to
handle just as well if you had used division and remainder operators.
The trickery is not only unnecessary, but (as I said previously) it gets
in the way of code reliability and maintainance.



More information about the Comp.lang.c mailing list