Comparison of C++, Java, Python, Ruby and MATLAB OOP Example

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

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 article ( ), which compares implementations of a Red Black Tree binary search algorithm ( ).
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 was 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 ( )
* Comparison of C++ and MATLAB Using Object Oriented Application Example ( )
* MATLAB Classes and Object Oriented Programming Documentation ( )
For more information on MATLAB OOP, see product page:

Cite As

Stuart McGarrity (2024). Comparison of C++, Java, Python, Ruby and MATLAB OOP Example (, MATLAB Central File Exchange. Retrieved .

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!


Version Published Release Notes

Fixed broken link

Edited description.

Fixed broken links

Updated license

Added link to more information.

Fix error in HTML formatting.

Url edit to comparelanguages.html

Description edits

Edits to url listing

Trademark work.

Added trademarks.

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