File Exchange

image thumbnail

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

version 1.14.0.1 (14.4 KB) by Stuart McGarrity
RedBlack Tree Binary Search Example Used to Compare of C++, Java™, Python, Ruby and MATLAB® Code

13 Downloads

Updated 01 Sep 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This example adds MATLAB® to the list of languages in this C++ vs Java vs Python vs Ruby: a first impression (http://web.archive.org/web/20100420080552/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 )

For more information on MATLAB OOP, see product page: http://www.mathworks.com/discovery/object-oriented-programming.html

Comments and Ratings (17)

Céldor

Céldor (view profile)

Verys useful. THanks :)

hiha

hiha (view profile)

Why doesn't the matlab test function run ?

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).

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!

Abel Brown

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

madhu j

pooooo mistry

want some detail info

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.

ogbonna christian. c

naing lwin

i want to know matlab ODE program

naing lwin

i want to know ODE program.

radhe shyam

Shaikh Noora Alam

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

Thanks

indira cristina conceição

this matlab is very good

lucas veiga

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)

mehemt sanbe

5

Updates

1.14.0.1

Updated license

1.14.0.0

Added link to more information.

1.13.0.0

Changed http://www.dmh2000.com/* links to http://web.archive.org/web/20100420080552/http://www.dmh2000.com/*

1.11.0.0

Fix error in HTML formatting.

1.10.0.0

Url edit to comparelanguages.html

1.9.0.0

Description edits

1.8.0.0

Edits to url listing

1.6.0.0

Trademark work.

1.1.0.0

Added trademarks.

1.0.0.0

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

Fix summary and Video URL

Resize image

Reformat

Resize image

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

View the winning live scripts from faculty and students who participated in the recent challenge.

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

comparelanguages/MATLAB_Code/