3.875

3.9 | 8 ratings Rate this file 325 downloads (last 30 days) File Size: 11.64 KB File ID: #18972

Comparison of C++, Java, Python, Ruby and MATLAB Using Object Oriented Example

by Stuart McGarrity

 

28 Feb 2008 (Updated 03 Oct 2009)

Code covered by BSD License  

RedBlack Tree Binary Search Example Used to Compare of C++, Java™, Python, Ruby and MATLAB® Code

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

This example adds MATLAB® to the list of languages in this C++ vs Java vs Python vs Ruby: a first impression (http://www.dmh2000.com/cjpr/ ) article at www.dmh2000.com, which compares implementations of a Red Black Tree binary search algorithm (http://www.cs.auckland.ac.nz/software/AlgAnim/red_black.html ).

The side by side code comparison shows the same simple object oriented example written in C++, Java, Python, Ruby and MATLAB. The MATLAB implementation uses the new object oriented features available in R2008a. This example is designed to help programmers familiar with these other languages learn object oriented programming practices in MATLAB.

How to Compare the Languages

Click download, then save and unzip the files to a folder. Open the comparelanguages.html file. The code for two languages is displayed side-by-side in two frames. You select which two languages to compare by clicking on the links at the top of each frame. Note that, unlike most of the other languages, you cannot currently put more than one class in a single MATLAB class definition file, so a fake combined file with the two classes and the test function (that does not run) is used for the side-by-side HTML comparison. The MATLAB code is contained in the sub folder called MATLAB_Code. The equivalent C++, Java, Python and Ruby code is available from the dmh2000 web site.

Although this example does let you compare the object oriented syntax of these languages, it does not compare the languages' ability to develop technical computing applications such as for signal processing, image processing, financial modeling, etc, for which MATLAB is designed.

Other resources for learning object orient programming in MATLAB include:

* Defining Classes Video Tutorial - 11 min (http://tinyurl.com/29cdle )

* Comparison of C++ and MATLAB Using Object Oriented Application Example (http://tinyurl.com/2zkhgu )

* MATLAB Classes and Object Oriented Programming Documentation (http://tinyurl.com/2z8mba )

MATLAB release MATLAB 7.6 (R2008a)
Zip File Content  
Published M Files Comparison of C++, Java, Python, Ruby and MATLAB Using Object Oriented Example, MATLABCombined
HTML Files lnav.html,
RedBlack Tree Example: Comparison of C++, Java, Python, Ruby and MATLAB,
rnav.html
Other Files license.txt,
MATLAB_Code/NodeVisitor.m,
MATLAB_Code/RedBlackTree.m,
MATLAB_Code/test_RedBlackTree.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
10 Mar 2008 mehemt sanbe

5

11 Mar 2008 Ernst Kloppenburg

1) in the Matlab implementation, the NodeVisitor class is not anonymous. The comment in Line 229 should be changed.

2) getter and setter methods for val and color should be implemented (for encapsulation, so the class internals can later be changed without changing its users)

13 Mar 2008 lucas veiga  
24 Mar 2008 indira cristina conceição

this matlab is very good

22 Apr 2008 Shaikh Noora Alam

Fantastic efforts, Congratulations!! Is it possible to send a CD compling all the demos for ready reference.

Thanks

08 May 2008 radhe shyam  
16 May 2008 naing lwin

i want to know ODE program.

16 May 2008 naing lwin

i want to know matlab ODE program

02 Jun 2008 ogbonna christian. c  
24 Aug 2008 Adrian D

Your effort is appreciated, but this comparison needs improvement. You've neglected to use language-specific idioms and techniques, making this into little more than a comparison of syntax. That's OK, but I believe the purpose of language comparisons is to highlight useful features. Programmers can write C++ code in any OO language, which seems to be what happened here.

27 Sep 2008 pooooo mistry

want some detail info

11 Dec 2008 shayam j  
08 Jun 2009 Abel Brown

Great non-trivial example! I know OO already so this was great for syntax, organization etc. Helped me out a lot!

29 Sep 2009 Cris Luengo

What Adrian said.

Handle behavior was not added to custom classes so that you could go around and translate C++ thinking into MATLAB!

For example, the NodeVisitor class is totally superfluous, and should just be a function (it has no data!). I also don't see why a MATLAB class would need a COPY method, it always exists implicitly through the assignment operator.

There is a </span> missing at the end of line 6 of the program in RBMATLAB.html, all the code is green!

03 Oct 2009 Stuart McGarrity

Yes, I agree that this is a pure translation / syntax comparison, intended to help programmers of these languages, become familiar with MATLAB OO syntax. It could be implemeted in a way more appropriate for MATLAB (while loosing the direct syntax comparison). I would encourage anyone to submit a new version of the code that does this. (I will fix the HTML typo - Thanks).

03 Nov 2009 hiha

Why doesn't the matlab test function run ?

Please login to add a comment or rating.
Updates

Resize image

01 Mar 2008

Reformat

01 Mar 2008

Resize image

03 Mar 2008

Fix summary and Video URL

11 Mar 2008

Corrected mistake in comments, found by reviewer, referring to 'anonymous' class

20 Jul 2009

Added trademarks.

29 Jul 2009

Trademark work.

25 Sep 2009

Edits to url listing

25 Sep 2009

Description edits

25 Sep 2009

Url edit to comparelanguages.html

03 Oct 2009

Fix error in HTML formatting.

Tag Activity for this File
Tag Applied By Date/Time
whitepaper Stuart McGarrity 22 Oct 2008 09:51:01
article Stuart McGarrity 22 Oct 2008 09:51:01
paper Stuart McGarrity 22 Oct 2008 09:51:01
c Stuart McGarrity 22 Oct 2008 09:51:01
java Stuart McGarrity 22 Oct 2008 09:51:01
python Stuart McGarrity 22 Oct 2008 09:51:01
ruby Stuart McGarrity 22 Oct 2008 09:51:01
matlab Stuart McGarrity 22 Oct 2008 09:51:01
object oriented Stuart McGarrity 22 Oct 2008 09:51:01
tree Stuart McGarrity 22 Oct 2008 09:51:01
redblack Stuart McGarrity 22 Oct 2008 09:51:01
article Malcolm Greene 14 Jun 2009 11:22:29
article Malcolm Greene 14 Jun 2009 11:22:30
matlab Malcolm Greene 14 Jun 2009 11:22:30
c Malcolm Greene 14 Jun 2009 11:22:36
paper Malcolm Greene 14 Jun 2009 11:22:39
potw Shari Freedman 23 Oct 2009 11:50:56
ruby Nezar 25 Oct 2009 01:13:58
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com