June 9, 2004 5:19 PM
Upon reading the C++ Standard Library Style Guidelines (DRAFT 2001-01-15) many days back, I came to the conclusion that a lot of coding style that I was so used to were considered deprecated. Even though guidelines are not rules and need not be adhered to in a strict manner, they do increase readability by a substantial factor.
This was one of the common
mistakes cases of bad
style of coding that I used to follow. Ugh, unlearning is so uncool!
char* a = "Hello"; char& b = *a; //Not char *a = "Hello"; char &b = *a;
The reason given is:
In C++, definitions are mixed with executable code. Here, p is being initialized, not *p. This is near-universal practice among C++ programmers; it is normal for C hackers to switch spontaneously as they gain experience.
Another one that caught my eye concerned with keywords such as extern, static, export, explicit, inline, etc. They go on the line above the function name.
virtual int foo() //Not virtual int foo()
The reason for this is:
GNU coding conventions dictate return types for functions are on a separate line than the function name and parameter list for definitions. For C++, where we have member functions that can be either inline definitions or declarations, keeping to this standard allows all member function names for a given class to be aligned to the same margin, increasing readability.