Friday, May 21, 2010

How to improve coding standards?

Given that programming is the stuff of thought, a "coding standard" should be able to improve that thinking. But my thinking isn't the same as yours.





So, if a "coding standard" isn't really there to help you program, then what is it for?





It is to help other programmers deal with your code. Which means that your coding standard is their coding standard. Adopt to them. Use automatic formatting tools (indent for C) if at all possible.





A corollary is that you should (almost) never invent your own coding standard. Use K%26amp;R for C, or Stroustrup for C++. Follow the conventions established. The main point is consistency, which the maintainers should thank you for.





Beyond these simple guidlines, you haven't stated where you are starting from, so I will list some "pet peeves" --





1 - Microsoft editors that don't believe a tab is to a column of a multiple of 8. Very annoying.





2 - Use of lines that are greater than 72 columns in length.





3 - useOfStrangeVariableNamesThatAreTooLong (gives me a headache -- why not strange_var? and see point 2).





4 - ppszHungarianNotation. Complete misuse of of a good idea. Making it a very dumb idea.





5 -


Function Name: strlen


Inputs: char * s - string that is zero terminated


Outputs: unsigned int - length of the string


Notes:


Author:


Date Revised:





Preferred:





/* return the length of the string */


unsigned int strlen(char *s)


{


...


}





I can't keep all those damn comments straight! If you want literary programming, use a tool that does it!





6 - Useless comments:





++i; /* increment i */





I will beat you. if you did:





#define INCREMENT(x) ++(x)


...


INCREMENT(i);





I would still beat you -- only less (I would assume that you are either (1) incapable of learning or (2) are moving from a different language).





7 - Misnaming, or obfuscating. If you use "delete" I assume that you mean delete, and not insert. If you use "i" I assume you mean an integer or index, or complex number and not the customer name.





That's the basic list. Please note that I reserve the right to beat you if I have to fix code that you wrote (in any language) that violates these basic principles.

How to improve coding standards?
Uhhh.. your Q is very vague - I could write novels on this. What exactly are you referring to? Commenting code? Creating secure code? Following naming conventions? Encapsulation? ..............


No comments:

Post a Comment