Things not to do in software, i

Define multiple symbolic constants that replace integer literals. If you have a bunch of functions that return 0 for success and -1 for error, then don’t do this:

#define ERROR -1
#define OK 0
#define ADD_ERR -1
#define ADD_OK 0
#define SEND_OK 0
#define SEND_ERR -1
#define RECV_ERR -1
#define RECV_OK 0

int func()
{
/* stuff */
if(/*something bad*/)
return ERROR;
else
return OK
}

int add()
{
/* add here */
return ADD_OK;
}

int send()
{
if(/*send ok*/)
return SEND_OK;
else
return SEND_ERR;
}

int recv()
{
if(/* receive packet successfully */)
return RECV_OK
else
return RECV_ERR;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>