{"id":221,"date":"2010-03-11T19:07:08","date_gmt":"2010-03-11T19:07:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2010\/03\/11\/dougs-top-10-matlab-code-practices-that-make-me-cry\/"},"modified":"2016-02-02T10:37:09","modified_gmt":"2016-02-02T15:37:09","slug":"dougs-top-10-matlab-code-practices-that-make-me-cry","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2010\/03\/11\/dougs-top-10-matlab-code-practices-that-make-me-cry\/","title":{"rendered":"Doug&#8217;s &#8220;Top 10 MATLAB code practices that make me cry&#8221;"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <h1>Doug's \"Top 10 MATLAB code practices that make me cry\"<\/h1>\r\n   <p>This week, Doug's <a href=\"https:\/\/blogs.mathworks.com\/videos\/2010\/03\/08\/top-10-matlab-code-practices-that-make-me-cry\/\">blog<\/a> focuses on what he considers to be some poor programming practices he's seen in MATLAB code.\r\n   <\/p>\r\n   <p>I agree with much of his list, including, despite the comments, the nix on global variables.  Assuming memory is an issue,\r\n      I would either do what one user suggests, create a handle class, or I would use nested functions.\r\n   <\/p>\r\n   <p>What are coding practices in MATLAB that you don't like to see?  Let's add to Doug's list <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=221\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_ce0c3900db644ba78e3455918473ac69() {\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='ce0c3900db644ba78e3455918473ac69 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ce0c3900db644ba78e3455918473ac69';\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        author = 'Loren Shure';\r\n        copyright = 'Copyright 2010 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 author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\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      \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_ce0c3900db644ba78e3455918473ac69()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.10<br><\/p>\r\n<\/div>\r\n<!--\r\nce0c3900db644ba78e3455918473ac69 ##### SOURCE BEGIN #####\r\n%% Doug's \"Top 10 MATLAB code practices that make me cry\"\r\n% This week, Doug's \r\n% <https:\/\/blogs.mathworks.com\/videos\/2010\/03\/08\/top-10-matlab-code-practices-that-make-me-cry\/ blog>\r\n% focuses on what he considers to be some poor programming practices he's\r\n% seen in MATLAB code.  \r\n%\r\n% I agree with much of his list, including, despite the comments, the nix\r\n% on global variables.  Assuming memory is an issue, I would either do what\r\n% one user suggests, create a handle class, or I would use nested\r\n% functions.\r\n%\r\n% What are coding practices in MATLAB that you don't like to see?  Let's\r\n% add to Doug's list <https:\/\/blogs.mathworks.com\/loren\/?p=221 here>.\r\n\r\n##### SOURCE END ##### ce0c3900db644ba78e3455918473ac69\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Doug's \"Top 10 MATLAB code practices that make me cry\"\r\n   This week, Doug's blog focuses on what he considers to be some poor programming practices he's seen in MATLAB code.\r\n   \r\n   I agree... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2010\/03\/11\/dougs-top-10-matlab-code-practices-that-make-me-cry\/\">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\/221"}],"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=221"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":1338,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/221\/revisions\/1338"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}