{"id":842,"date":"2014-01-29T10:05:13","date_gmt":"2014-01-29T15:05:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=842"},"modified":"2014-01-20T16:06:13","modified_gmt":"2014-01-20T21:06:13","slug":"coding-best-practices-a-good-read","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2014\/01\/29\/coding-best-practices-a-good-read\/","title":{"rendered":"Coding Best Practices &#8211; A Good Read"},"content":{"rendered":"<div class=\"content\"><h3>Coding Best Practices - A Good Read<\/h3><p>I have written blogs before on coding best practices in MATLAB and they have always generated a lot of great feedback.  I recently came across a <a href=\"http:\/\/www.plosbiology.org\/article\/info%3Adoi%2F10.1371%2Fjournal.pbio.1001745#s2\">language-neutral list of best practices<\/a> for scientific computing, written by Greg Wilson of <a href=\"http:\/\/software-carpentry.org\/\">Software Carpentry<\/a>.<\/p><p>If you don't want to start by reading the whole article, I strongly encourage you to read <a href=\"http:\/\/software-carpentry.org\/blog\/2014\/01\/best-practices-has-been-published.html\">Greg's summary<\/a>.   He breaks the practices into eight categories. I have to say, I think they are very well stated, starting with \"Write programs for people, not computers.\".<\/p><p>I have to say, I think Greg hit the nail on the head.<\/p><p><b>Do You Violate these Best Practices?<\/b><\/p><p>The most frequent violations I see include not using a debugger and, a lot of code is trying to optimize it before being sure it is truly correct.  Which practice is your Achilles' heel?  Let me know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=842#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_5e4c239644024ffc8663c1f31b2c64fb() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='5e4c239644024ffc8663c1f31b2c64fb ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5e4c239644024ffc8663c1f31b2c64fb';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_5e4c239644024ffc8663c1f31b2c64fb()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n5e4c239644024ffc8663c1f31b2c64fb ##### SOURCE BEGIN #####\r\n%% Coding Best Practices - A Good Read\r\n% I have written blogs before on coding best practices in MATLAB and they\r\n% have always generated a lot of great feedback.  I recently came across a\r\n% <http:\/\/www.plosbiology.org\/article\/info%3Adoi%2F10.1371%2Fjournal.pbio.1001745#s2\r\n% language-neutral list of best practices> for scientific computing,\r\n% written by Greg Wilson of <http:\/\/software-carpentry.org\/ Software\r\n% Carpentry>.\r\n%\r\n% If you don't want to start by reading the whole article, I strongly\r\n% encourage you to read\r\n% <http:\/\/software-carpentry.org\/blog\/2014\/01\/best-practices-has-been-published.html\r\n% Greg's summary>.   He breaks the practices into eight categories. I have\r\n% to say, I think they are very well stated, starting with \"Write programs\r\n% for people, not computers.\".\r\n%\r\n% I have to say, I think Greg hit the nail on the head.\r\n%\r\n% *Do You Violate these Best Practices?*\r\n%\r\n% The most frequent violations I see include not using a debugger and, a\r\n% lot of code is trying to optimize it before being sure it is truly\r\n% correct.  Which practice is your Achilles' heel?  Let me know\r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=842#respond here>.\r\n\r\n##### SOURCE END ##### 5e4c239644024ffc8663c1f31b2c64fb\r\n-->","protected":false},"excerpt":{"rendered":"<p>Coding Best Practices - A Good ReadI have written blogs before on coding best practices in MATLAB and they have always generated a lot of great feedback.  I recently came across a language-neutral... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2014\/01\/29\/coding-best-practices-a-good-read\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,14],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/842"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=842"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/842\/revisions"}],"predecessor-version":[{"id":854,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/842\/revisions\/854"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}