Re: How to write elegant C coding

From: Horst von Brand
Date: Wed Jan 05 2005 - 10:21:03 EST


krishna <krishna.c@xxxxxxxxxxxxxxxxxx> said:

[...]

> What I mean is both elegant and _efficient_ best practices in C coding.

Look for "Writing Efficient Programs", by Jon Bentley (sadly out of print),
and his "Programming Pearls" (2nd edition).

Keep in mind that "efficient" is mostly a thing of overall organization and
careful design (and data structure definition), not detailed programming.
Microoptimizations are usually counter-productive, at least by making the
code unnecessarily hard to read; current compilers aim at generating code
from "normally written C" that is at least as good as that a competent
assembly programmer would write with care (and often writing "more
efficient source code" just confuses the compiler into giving worse
results). Better aim at understandable, easy to get right code. If you
_measure_ later that it is too slow/large/..., _then_ go back and see how
to make it better. So Documentation/CodingStyle is an excellent starting
point.
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/