Every project has its own style guide: a set of conventions about how to write code for that project. Some managers choose a basic coding rules, others prefer very advanced ones and for many projects no coding rules are specified, and each developer uses his style.
The coding style has a big impact on the source code readability, investing some hours to train developers, and doing periodically a code review is always good to make the code easy to maintain and evolve.
Many resources exist talking about the better coding rules to adopt. However even if thousands of practices are recommended, the developers focus only on some of them.
In case of C++ here’s the list of the 10 most voted best practices in our C++ best practices repository:
1- Always compile at the highest warning level possible: A lot of bugs can be avoided by paying attention to compiler diagnostics
3-If you can exit a function early, you should: Early exits out of a function, specially through guard clauses at the top of a function are preferred since they simplify the logic further down in the function.
4- Avoid methods with too many local variables: Methods where NbVariables > 8 are hard to understand and maintain. Methods where NbVariables > 15 are extremely complex and must be refactored
5- Avoid types with too many fields: Types where fields count > 20 might be hard to understand and maintain but there might be cases where it is relevant to have a high number of fields.
6- Avoid types with too many methods: Types where methods count > 20 might be hard to understand and maintain but there might be cases where it is relevant to have a high number of methods.
As we can remark the most voted rules are the most basic and generic ones, every developer could just use the common sens to respect them, and these rules may be applied to any other language.