{"id":2280,"date":"2015-04-10T19:04:07","date_gmt":"2015-04-10T18:04:07","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?page_id=2280"},"modified":"2015-06-02T12:10:57","modified_gmt":"2015-06-02T11:10:57","slug":"good-c-code","status":"publish","type":"page","link":"http:\/\/roboblog.fatal-fury.de\/?page_id=2280","title":{"rendered":"Good C++ Code"},"content":{"rendered":"<p>My tips for a more readable, safer and reuseable code!<br \/>\nThe tips are very very simple. Everyone can use them in daily programming!<\/p>\n<p><strong>Articles<\/strong><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2158\" title=\"Five Myths about C++ BUSTED!\">Five Myths about C++ BUSTED!<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2349\" title=\"integer overflow debugger trap\">integer overflow debugger trap<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2309\" title=\"Passing random generators around (functor)\">Passing random generators around (functor)<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2304\" title=\"Calling multiple random generator in parallel c++11\">Calling multiple random generator in parallel c++11<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2271\" title=\"Polymorphie virtual abstract pure deconstrutor WTF?\">Polymorphie virtual abstract pure deconstrutor WTF?<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2216\" title=\"rosettacode - Simple moving variance\">rosettacode - Simple moving variance<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2196\" title=\"rosettacode - Simple moving average\">rosettacode - Simple moving average<\/a><br \/>\n<a href=\"http:\/\/roboblog.fatal-fury.de\/?p=2050\" title=\"raw speed of C using OO with C++\">raw speed of C using OO with C++<\/a><\/p>\n<p><strong>Common editing<\/strong><\/p>\n<li>Intend your code. Usually use 4 whitespaces.<\/li>\n<li>Never use tabs to intend, only spaces!<\/li>\n<li>Structure the code in logical blocks. Use one newline between the blocks.<\/li>\n<li>Use brackets! Use { }! Use ()! Its much more safer and readable! Use {} after every for if while! Don't be lazy. Use auto completion if you are lazy. One exception for this rule: for throwing exceptions. e.g. if(false) throw \"Shit\"\n<p><strong>C and C++ mixing<\/strong><\/p>\n<li>Never mix C and C++<\/li>\n<li>Don't use the old C include files with prefix \".h\" e.g. math.h Instead use cmath<\/li>\n<li>Always write the full standard namespace when using standard functions e.g. std::abs<\/li>\n<li>Write \"using namespace myspace\" only for non-standard namespaces.<\/li>\n<li>Never write \"using namespace\" in header files. Only in cpp files.<\/li>\n<p><strong>Loops<\/strong><\/p>\n<li>The first running variable in a loop is \"i\", then \"j\" and \"k\".<br \/>\nNever use something like \"ii\", \"iii\". Don't use \"l\" (lower L) eiher, it looks too much like \"i\"<\/li>\n<li>Prefer for() loops for while() loops. They have a clearer syntax how log the loop is running. And you prevent endloss loops.<\/li>\n<li>Every while() loop can be written as for() loop()<\/li>\n<p><strong>common function calls<\/strong><\/p>\n<li>Pass non derived POD object as value. Like int float char<\/li>\n<li>Pass non-POD objects as const reference. This performs no deep-copy and the caller can be sure that his object is not modified.<\/li>\n<li>Pass by pointer only if you must modify the object! The caller knows throw the pointer notation that the object may be altered<\/li>\n<li>Pass functions objects by value???<\/li>\n<p><strong>get functions<\/strong><\/p>\n<li>Functions which returns a variable and <strong>not change the object<\/strong> must be marked with \"<strong>const<\/strong>\"<\/li>\n","protected":false},"excerpt":{"rendered":"<p>My tips for a more readable, safer and reuseable code! The tips are very very simple. Everyone can use them in daily programming! Articles Five Myths about C++ BUSTED! integer overflow debugger trap Passing random generators around (functor) Calling multiple random generator in parallel c++11 Polymorphie virtual abstract pure deconstrutor WTF? rosettacode - Simple moving [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2280","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2280"}],"version-history":[{"count":17,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2280\/revisions"}],"predecessor-version":[{"id":2390,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2280\/revisions\/2390"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}