Using "this" in every MATLAB class

Why should I use "this" in every class in MATLAB? I think in C ++ I don't need to use "this" only if I want. Does this also take place in MATLAB?

+7
source share
1 answer

In short, you should use some explicit link.

First of all, unlike C ++ / C # / Java, where it is called this, you can use whatever name you want. The reason you should use explicit calls is the decision of the Matlab designers . The idea was to support Matlab vector operations on objects, as if they were Structures. Below is a snippet from the link above:

While languages ​​with an implicit object parameter provide the keyword "this" to access the implicit object, they usually do not require you to access the property through "this". If MATLAB had implicit properties, the logical extension of array-based objects will be indexing by nothing:
S = S + (k) .Value;

Edit: Following @AndrewJanke's good comment, I would like to add that MATLAB could have this as an implicit reference and only force it when indexing array-based objects. However, this approach was not chosen by MATLAB designers.

+9
source

All Articles