On this page that explains the use of inputParser class,
we see that every inputParser method call in the examples is of the form
methodname(object, arguments)
instead of
object.methodname(arguments)
For example
addRequired(p,'filename',@ischar)
instead of
p.addRequired('filename',@ischar)
where p is an instance if inputParser.
I would say that this makes it unclear where addRequired is coming from without having to search for it either though which or for the instantiation line in the code before it is being called. Having addRequired available in any context kind of breaks encapsulation, and seems to be the very opposite of what you would want from introducing OOP in the first place.
I suspect there is a good reason to sacrifice readability and write documentation in this particular way.
So my question is, is there any practical difference between "functional" and "OOP" syntax in MATLAB?
I'm afraid these syntaxes are not even fully equivalent, as can be learned from the following example:
Most importantly:
Now suppose we are sadists and want to write a function that behaves like that ourselves, investigating further we find that
cfit.coeffvaluesis simply a getter for a private property. Now if you look closely at the error above, you'd notice that it didn't even occur incfit.coeffvalues, but instead incfit.subsref!In conclusion,
from this we can learn, empirically, that the functional notation goes directly to the method in question, whereas the OOP notation first goes through the possibly overridden
subsrefmethod of the class. I guess if you want to make sure you're skipping any customsubsref, use functional notation.