| Projects Home | Tools | Autobuild | CVS | Doxygen |
If an item is marked as Required do not waste your time trying to convince me otherwise. Items marked WTD are worth a shot if you have strong feelings on the issue.
#ifdef protection blocks to prevent multiple includes. My preferred name scheme is __HEADERNAME_INCLUDED, so a typical header for a file defining buffer utilities would look like:/* * CVS Comment block */ #ifndef __BUFFER_UTILS_HEADER_INCLUDED #define __BUFFER_UTILS_HEADER_INCLUDED Code.... #endif
#include all of the other headers needed for the types used by the header and no others. An easy way to check conformance is to #include a header as the first line of the corresponding code file, e.g. if I am developing code for buffer utils in bufutils.h and bufutils.C, the first line after the CVS comment block in bufutils.C is:#include <bufutils.h>
if(x > 5){ if(x > 5){
y=2; y = 2;
z=5; z = 5;
} }else{
x = y+2; y = 4;
z = 10;
}
x = y+2;
while(x > 5){
x--;
y++;
}
Note: If you do not need braces, do not use them, since it is a waste of space. Always write:
if(x > 5) NOT: if(x > 5){
y = 10; y=10;
}
void
MyClass::MyMethod(int x, int y):
Initializer(x),
Initializer(y)
{
Body of the code
}
Code with hardcoded paths. Insane, tiring, etc.... Every language has facilities for dealing with paths and names. Use them. A program which only works on "Data.in" is next to useless. A program which only works on /home/student1/myfile.in is worse.
This applies to HTML pages and scripts as well as code. Unless a link is going off-site, it should be relative to the current page.
Verbose code. To increment a variable in C/C++, use x++; but never use x = x + 1;. In general your code should be as concise as possible, even sacrificing readability for those who are not expert C programmers.
Inefficient code. The following bit of insanity is all to frequent:
if(!strcmp(param, "-b")) p = 1; if(!strcmp(param, "-c")) p= 2; and so on....If you compared param to "-b" and found them to be the same, why are you comparing param to "-c" to the next selector? A better way of coding this is:
if(!strcmp(param, "-b")) p = 1; else if(!strcmp(param, "-c")) p = 2;or even better:
if(param[0] == '-')
switch(param[1]){
case 'b':
p =1;
break;
case 'c':
p = 2;
break;
}
This version avoids the large overhead of strcmp(). If you are really smart, you would not use any of these to compare parameters, but would instead be using the built-in function getopt() to handle parameter parsing.
| Projects Home | Tools | Autobuild | CVS | Doxygen |