Workaround MATLAB’s intellisense/auto-complete issues for user defined classes

This will be a short post, but a little wakeup call for myself, and others that may get annoyed by the same issue. The issue at hand is, that MATLAB does not seem to have fully functioning intellisense/auto-complete when dealing with a class definition that spans over multiple files. Let me elaborate…

Class definition organisation

Classes can be seen as blueprints for objects. Beside the inheritance and other class-like features, these classes can encapsulate a lot of functionality in the form of methods, yet with increasing functionality, the class definition file becomes very long. To circumvent this, it is possible to break the class definition from:

FooClass.m

into

@FooClass/FooClass.m
@FooClass/bar1.m
@FooClass/bar2.m
@FooClass/bar3.m

where FooClass is the class name and associated constructor call, and bar1 to bar3 are the methods of FooClass. Originally, FooClass.m contains both constructor and any further method definitions, but with the latter file hierarchy, FooClass.m only contains the constructor and “prototypes” of bar1 to bar3. The actual functionality of bar1 to bar3 is implemented in, respectively, the bar1.m to bar3.m files.

Very neat, but when you want to access a property, which in both cases are defined in FooClass.m, then the intellisense/auto-complete functionality in MATLAB does not work when writing code in any other file than FooClass.m 🙁

Fix or workaround

When defining a method function for a class definition in MATLAB, you always need to pass the class itself as the 1st argument. With my Objective-C and Swift background I usually call this argument self. Assuming property called self.name was declared in FooClass.m, then I could modify it from within bar1, but self.<tab> yields nothing.

When initialising a temporary object of this class in the workspace as self, then (what a surprise surprise) it works! Unfortunately, amending the source code does not update the intellisense/auto-complete list, despite the method becoming available to the programmer.

At the time of writing this post I was using MATLAB 2016b. Maybe they will have added this feature in 2017a or later…

Rant – sorry in advance

Surely a good programmer should not rely on tabbing through the code? YES! He or she should! Using long and descriptive names makes debugging much easier and the code incredibly clear, yet typing them is prone to errors and time consuming. Therefore, being able to auto-comple everything reduces the risks of typos and improves productivity. For now, I hope that my class definitions are all error free – I do consider myself a very competent programmer, but I’m human nonetheless.

You may wonder why I rant about something this trivial? MATLAB with all toolboxes that have been made available to us from by our university, would equate to a total of £72,785.00 if you wanted to buy it off the shelf! For a tool this powerful and so expensive one could assume to have fully working intellisense/auto-complete, right?

Don’t get me wrong, I like MATLAB a lot! It makes working and programming with our datasets and equations quite easy. Yet how is it that such a simple feature is not part of this expensive suite? Most free IDEs and their corresponding programming language have the capability of detecting and collecting all variables or properties that belong classes, objects, modules, packages, or whatever you are working with. Why do I need such an ugly “hack” in such a beautifully simple programming language? Argh!

Anyhow… 12 minute rant over, time to go home 😛

2 Responses to “ Workaround MATLAB’s intellisense/auto-complete issues for user defined classes ”

  1. Ainsmar Brown

    I feel your pain. Have not checked​ R2017a yet.

    • I tried in R2017a, and there is a small hope! Autocomplete works in the main class file (so in FooClass.m of the example above) but not in any method definition files 🙁 Maybe it’ll work in R2017b or later.

Leave a Reply

*
*