C/C++ Programming Style Guidelines



Example 8. Poor variable names
// Notice how redundant "stack" becomes.
template <Type>
class Stack {
public:
int stack_size;
add_item_to_stack(Type item);
...
};
Stack my_stack;
my_stack.add_item_to_stack(4);
int tmp = my_stack.stack_size;
5. Comments
In general, well written code should document itself. Clear, concise variable and
function names, consistent formatting and spatial structure, and clean syntactical
structure all contribute to readable code. Occasionally, however, complex logic will
benefit from explicit description. Be careful not to use comments to compensate for
poorly written code. If you find that your code requires many comments or is often
difficult to describe, perhaps you should be rewriting the code to make it simpler and
clearer.