7 January 2000
Because C++ is a markedly different language from C, good C++ code looks markedly different from good C code. Differences from good C style follow from these differences:
Names -- particularly, qualified names, and expressions and declarations in C++ are often much longer than in C.
Scoping in C++ is more complex than in C.
Types in C++ are semantically far more important than in C.
Local variable definitions in C++ are mixed in with other statements.
C++ includes constructs that don't exist in C.
C++ overloads syntactic elements even more heavily than C.
Semantics of some C++ constructs differ from C.
Rules below are based on some broad principles:
Direct expression of concepts in code is much better than annotation in comments.
Comprehensibility for maintainers, and robustness against changes during maintenance, are at least as important as convenience for coders.
Formatting should be deterministic and straightforward. Time spent thinking about formatting code is time better spent writing it.
Sources of subtle bugs should be given a wide berth.
Meaningless-busywork rules get ignored.
Next | ||
Guidelines |