{"id":2485,"date":"2009-10-23T11:01:49","date_gmt":"2009-10-23T11:01:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/10\/23\/object-oriented-programming-matlab-vs-others\/"},"modified":"2016-05-18T11:13:12","modified_gmt":"2016-05-18T15:13:12","slug":"object-oriented-programming-matlab-vs-others","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/10\/23\/object-oriented-programming-matlab-vs-others\/","title":{"rendered":"Object Oriented Programming (MATLAB vs others)"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/18972-comparison-of-c++--java--python--ruby-and-matlab-using-object-oriented-example\">\"Comparison of object oriented code\"<\/a> by our very own <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2962\">Stuart McGarrity<\/a>.\r\n\r\nTo some of you, this may be old news, but I know that not everyone is up to date on newer features. The new Object Oriented\r\nProgramming capability that was introduced in R2008a has been highlighted several times by <a href=\"https:\/\/blogs.mathworks.com\/loren\/2008\/08\/18\/when-to-create-classes-in-matlab\/\">Loren<\/a>, <a href=\"https:\/\/blogs.mathworks.com\/videos\/2008\/07\/07\/advanced-matlab-class-system-for-oop-in-matlab-introduction\/\">Doug<\/a>, and <a href=\"https:\/\/blogs.mathworks.com\/steve\/2008\/03\/21\/matlab-76-r2008a\/\">Steve<\/a>.\r\n\r\nThis entry by Stuart provides a nice syntax comparisons between MATLAB and a few of the common object oriented languages (C++,\r\nJava, Python, Ruby). Take a look at the published HTML to read about it and get a quick side-by-side comparison of these languages.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/codecompare.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\n<i>Note: as Stuart mentions in the comments, this is a syntax comparison, and it is not meant for showcasing best practices.\r\nThe <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_oop\/ug_intropage.html\">documentation<\/a> is a good place to get such info.<\/i>\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2485#respond\">Comments<\/a>?\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_dfd1458cbd9c42a6970acdc0831b41f7() {\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='dfd1458cbd9c42a6970acdc0831b41f7 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' dfd1458cbd9c42a6970acdc0831b41f7';\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 = 'Jiro Doke';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<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>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.9<\/p>\r\n\r\n<\/div>\r\n<!--\r\ndfd1458cbd9c42a6970acdc0831b41f7 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007 % Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/18972-comparison-of-c++--java--python--ruby-and-matlab-using-object-oriented-example % \"Comparison of object oriented code\"> by our very own\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2962 % Stuart McGarrity>.\r\n%\r\n% To some of you, this may be old news, but I know that not everyone is up\r\n% to date on newer features. The new Object Oriented Programming\r\n% capability that was introduced in R2008a has been highlighted several\r\n% times by\r\n% <https:\/\/blogs.mathworks.com\/loren\/2008\/08\/18\/when-to-create-classes-in-matlab\/ % Loren>,\r\n% <https:\/\/blogs.mathworks.com\/videos\/2008\/07\/07\/advanced-matlab-class-system-for-oop-in-matlab-introduction\/ % Doug>, and <https:\/\/blogs.mathworks.com\/steve\/2008\/03\/21\/matlab-76-r2008a\/ % Steve>.\r\n%\r\n% This entry by Stuart provides a nice syntax comparisons between MATLAB\r\n% and a few of the common object oriented languages (C++, Java, Python,\r\n% Ruby). Take a look at the <https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/18972\/12\/content\/Description.html % published HTML> to read about it and get a quick side-by-side comparison\r\n% of these languages.\r\n%\r\n% <<codecompare.png>>\r\n%\r\n% _Note: as Stuart mentions in the comments, this is a syntax comparison,\r\n% and it is not meant for showcasing best practices. The <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/techdoc\/matlab_oop\/ug_intropage.html % documentation> is a good place to get such info._\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2485#respond Comments>?\r\n##### SOURCE END ##### dfd1458cbd9c42a6970acdc0831b41f7\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nJiro's pick this week is \"Comparison of object oriented code\" by our very own Stuart McGarrity.\r\n\r\nTo some of you, this may be old news, but I know that not everyone is up to date on newer... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/10\/23\/object-oriented-programming-matlab-vs-others\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2485"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2485"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2485\/revisions"}],"predecessor-version":[{"id":7315,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2485\/revisions\/7315"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}