
{"id":1957,"date":"2015-08-13T14:14:48","date_gmt":"2015-08-13T14:14:48","guid":{"rendered":"http:\/\/www.codergears.com\/Blog\/?p=1957"},"modified":"2015-08-13T14:16:51","modified_gmt":"2015-08-13T14:16:51","slug":"10-most-voted-c-best-practices","status":"publish","type":"post","link":"https:\/\/codergears.com\/Blog\/?p=1957","title":{"rendered":"10 most voted C++ best practices"},"content":{"rendered":"<p style=\"color: #333333;\"><span style=\"color: #000000;\">Every \u00a0project has its own style guide: a set of conventions about how to write code for that project.\u00a0<\/span>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.<\/p>\n<p style=\"color: #333333;\">The coding style has a big impact on\u00a0the 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.<!--more--><span id=\"more-163\"><\/span><\/p>\n<p style=\"color: #333333;\">Many resources exist talking about the better coding rules to adopt. However \u00a0even if\u00a0thousands of practices\u00a0are recommended, \u00a0the developers focus only on some of them.<\/p>\n<p style=\"color: #333333;\">In case of C++ here&#8217;s the list of the 10 most voted best practices in our <a href=\"http:\/\/codergears.com\/QACenter\/\">C++ best practices repository:<\/a><\/p>\n<p style=\"color: #333333;\">1- <a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=434&amp;qa_1=always-compile-at-the-highest-warning-level-possible\">Always compile at the highest warning level possible<\/a>:\u00a0<span style=\"color: #34495e;\">A lot of bugs can be avoided by paying attention to compiler diagnostics<\/span><\/p>\n<p style=\"color: #333333;\">2-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=280&amp;qa_1=code-that-is-not-used-commented-out-shall-be-deleted\">Code that is not used (commented out) shall be deleted<\/a><\/p>\n<p style=\"color: #333333;\">3-<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=323&amp;qa_1=if-you-can-exit-a-function-early-you-should\">If you can exit a function early, you should<\/a>:\u00a0<span style=\"color: #34495e;\">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.<\/span><\/p>\n<p style=\"color: #333333;\">4-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=19&amp;qa_1=avoid-methods-with-too-many-local-variables\">Avoid methods with too many local variables<\/a>:\u00a0<span style=\"color: #34495e;\">Methods where NbVariables &gt; 8 are hard to understand and maintain.\u00a0<\/span><span style=\"color: #34495e;\">Methods where NbVariables &gt; 15 are extremely complex and must be refactored<\/span><\/p>\n<p style=\"color: #333333;\">5-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=22&amp;qa_1=avoid-types-with-too-many-fields\">Avoid types with too many fields<\/a>:\u00a0<span style=\"color: #34495e;\">Types where fields count &gt; 20 \u00a0\u00a0might be hard to understand and maintain but there might be cases where it is relevant to have a high number of fields.<\/span><\/p>\n<p style=\"color: #333333;\">6-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=21&amp;qa_1=avoid-types-with-too-many-methods\">Avoid types with too many methods<\/a>:\u00a0<span style=\"color: #34495e;\">Types where methods count &gt; 20 might be hard to \u00a0understand and maintain but there might be cases where it is relevant to have a high number of methods.<\/span><\/p>\n<p style=\"color: #333333;\">7- <a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=18&amp;qa_1=avoid-too-big-methods\">Avoid too big\u00a0types<\/a><\/p>\n<p style=\"color: #333333;\">8- <a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=16&amp;qa_1=avoid-too-complex-methods\">Avoid too complex methods<\/a><\/p>\n<p style=\"color: #333333;\">9-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=17&amp;qa_1=avoid-methods-with-too-many-parameters\">Avoid methods with too many parameters<\/a><\/p>\n<p style=\"color: #333333;\">10-\u00a0<a href=\"http:\/\/codergears.com\/QACenter\/index.php?qa=18&amp;qa_1=avoid-too-big-methods\">Avoid too big methods<\/a><\/p>\n<p style=\"color: #333333;\">As we can remark the most voted rules\u00a0are 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every \u00a0project has its own style guide: a set of conventions about how to write code for that project.\u00a0Some 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\u00a0the source code &hellip; <a href=\"https:\/\/codergears.com\/Blog\/?p=1957\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 most voted C++ best practices&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1957"}],"version-history":[{"count":17,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1957\/revisions"}],"predecessor-version":[{"id":1974,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1957\/revisions\/1974"}],"wp:attachment":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}