Variable names should be self-documenting; e.g., nsamps
for
"number of samples", i_fd
for "input file descriptor", etc. The
meaning of a variable name, and the usage of the corresponding variable,
should be invariant throughout the program.
In general, names must be longer than 1 character. However, the following traditional 1-character local names may be used:
c ASCII character i,j,k array or loop index m,n count or loop limit p,q pointer s pointer-to-string
The following 1-character prefixes are also widely used in IPW source code:
i_ input image m_ mask image n number of o_ output image
The suffix "p"
indicates "pointer to". A double-indirect pointer
is indicated by "pp"
.
Long names should differ from one another by more than 2 characters, or by
an obvious prefix (not suffix). Certain characters that are easily confused
(e.g., 1 , l ,and I ;and 0 , O ,and Q) should not be relied on to distinguish
different names. Finally, possible phonetic confusion between a name's
"sound" and its meaning should be avoided; a classic example is
inch
for "input character"
[Plum 1984].
The preferred way of indicating word breaks in names is by an underscore. Using capitalization is also acceptable.
Here are the naming conventions for IPW:
"typedef"
s - lower-case and end in "_t"
for
scalar types; upper-case and end in "_T"
for aggregate
types.
geohmake
constructs a new image geodetic header.
Global variables and functions that are private to a module (i.e., shared by a group of functions, but not accessed outside that group) should have a leading underscore to indicate that their access is limited to the module.
Example:
#define PIPE_BUF 4096 #define DIM(a) ( sizeof(a) / sizeof(a[0]) ) #define STRSIZE(s) ( strlen(s) + 1 ) typedef int bool_t; typedef struct node { int datum; struct node *prev; struct node *next; } LIST_T; static int Line_number; /* prefered */ static int LineNumber; /* acceptable */ char fooPrint( int i_fd, /* input image */ pixel_t *buffer, /* pixel buffer */ int bufSize) /* length of buffer */ { ... }