lallous said:
It is a matter of style..
I often use this:
int iCounter, i, j, iFlag;
int nMax, nMin, nCount, n, k;
char *szName, *Buffer, p, pName, pBuffer2;
double dblX, dblY, dblZ;
Just a small addition to this - if you are using global variables then I
prefix them with g or g_
e.g.
char gszAppName[] = "...";
Wait... you forgot the following rules:
If you have more than one object with the same function, use
numerical suffixes _1, _2...
int scancnvt(int naX_1, int naY_1, int naX_2, int naY_2);
Use typedefs to clarify code:
typedef struct Spoint *pSpoint_tt; /* _t is reserved by POSIX */
Pointers involved in linked-list manipulation should be
appropriately named:
#define gpNULL NULL
pSpoint_tt gpLLroot = gpNULL;
If a linked data structure is expected to have a particular shape
for most of its lifetime, use the standard chemical nomenclature:
pSpoint_tt cyclohexagpCLLroot; /* circular linked list
with six elements */
pSpoint_tt cyclohexegpDLLroot; /* doubly linked list */
pSpoint_tt benzegproot; /* 1.5-linked list */
If two objects are used in a very similar fashion throughout a
function, then they should have very similar names - this is
the OO doctrine of "form follows function."
double rPixelAddrX, rPixelAddrY; /* measured from (cx, cy) */
int iPixelAddrX, iPixelAddrY; /* measured from (0, 0) */
When used in complex expressions like
nlRadiusy_1 = dSQR(iPixelAddrX-cx) + dSQR(rPixelAddrY);
nlRadiusy_1 /= 2;
it is not immediately obvious what the programmer's intent was.
This is called "data hiding," and is a concept central to the
study of job security.
The encoding of type information in variable names should not be
restricted only to integers and strings, however. More complex
types, such as pointers to functions, must be covered as well.
typedef int (*pIntFpaCVPCVPap_tt)(const void *, const void *);
pIntFpaCVPCVPap_tt pIntFpaCVPCVPapQSort = qsort;
Note the usage of pa...ap to represent parentheses in the type
name. This is an elegant solution to the ugliness of C's type
system, and should be used wherever possible to simplify your
code. Evangelistic tracts in the comment blocks may also help
convert the programmers who must maintain your code.
I hope these helpful hints give you something to think about.
-Arthur
TWAJS