[H-GEN] C code.

Martin Pool mbp at pharos.com.au
Sun Nov 2 00:01:47 EST 1997


On Mon, 27 Oct 1997, Andrae Muys wrote:

> Well after that last C post I thought I'd solicit comments on my own
> coding style (constructive please, flames < /dev/random > /dev/null).
> Anyone who's interested can have a look at
> http://www.uq.edu.au/~cmamuys/source_downloads/hash.[ch] constructive
> critism appreciated.

0. If you care enough to code that nicely :-), you probably should be
using RCS or CVS to do version numbers, change logs, and version control. 

1. The sanity checks

        if (size < 0) {
                HASH_REPORT("Precondition violation in intHashInit().\n");
                return NULL;
        }

are very good.  You might care to bracket them in #ifdef HASH_DEBUG so
that people can build a faster version without those checks when they're
"sure" they've got all the bugs out.

2. Studies have found that 8-character indents consistently produce lower
comprehension than 4-character indents in the same program: lines have to
be wrapped more, the indents are too dominant, and the eye doesn't move
naturally from line to line.  Seriously.

3. The function descriptions are not written at the level of intent.  That
is, they tend to explain 'how', not 'what'.

4. You might consider returning standard codes from errno.h, rather than
custom ones: EEXIST, ENOENT, and so on.

"Writing Solid Code" is very good in this area.

This is meant to be constructive.  Comments on some code I've just
released to 

  http://www.pharos.com.au/gdbm/

would be appreciated: it contains both Java and C code.

--
Martin Pool, Pharos

----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe



More information about the General mailing list