Saturday, October 10, 2009

Coding standards do no harm

Coding standards aid in picking up new code faster, it can help in debugging too. For example it's almost safe to skip a const qualified method while debugging a problem (just make sure that there are no mutable members).

Lately I had crazy time debugging a problem that eventually boiled down to non adherence of coding standards. Here it goes ...

A new API that looks as simple as below was added to a self sufficient component which compiles clean after the change was made.
    int process_data( const char * str, char delim = '  ' );
Suddenly another component that depends on the modified header fails to compile with error C2143: missing ')' before 'string'. That's a bit of shock!. By the way the other component doesn't use the new API at all.

It turned out that other component has defined a macro which is neither long nor uses UPPER_CASE. Of course it's their choice!
    #define delim TEXT(" ")        // and
#define TEXT( str ) L##str // just token pasting ...
You are punished for using a simple looking identifier (delim) and it takes efforts to understand that you are being punished!