DEV Community

dinhanhx
dinhanhx

Posted on

How stupid is Matlab OOP?

Let write a normal class in Java first

public class Car {
    private int wheels;
    public void setWheels(int new_wheels) {
        wheels = new_wheels;
    }
}
Enter fullscreen mode Exit fullscreen mode

Keep in mind that Java is a lower-language than Matlab. Now you might ask in Matlab it should simpler than the Java code. Guess what. It's no.

classdef Car
    properties (Access = public)
        wheels
    end
    methods (Access = private)
        function setWheels(new_wheels)
            wheels = new_wheels
        end
    end
end
Enter fullscreen mode Exit fullscreen mode

In Matlab, you have to define blocks (methods and properties) to separate functions and variables. What even more confusing is that MathWork calls Access an attribute. (Method Attributes, Properties attributes). In UML notation or any language providing OOP, attributes mean object/class variables or properties. The right words for public or private are modifiers (in Java), specifiers (in C++). As a result, when you are talking with other engineers (who are not proficient in matlab), you could make them confused with words.

Now we will add a public integer attribute plate to class Car

in Java

private int plate;
Enter fullscreen mode Exit fullscreen mode

in Matlab

properties (Access = private)
    plate
end
Enter fullscreen mode Exit fullscreen mode

You see unnecessary keywords and characters in matlab. If the researchers or the engineering need fast prototyping, matlab isn't for them. Ironically, Matlab claim to be the right language for scientific computing.

Top comments (0)