MATLAB Answers

0

Tracking instantiation when running an OOP program

Asked by Andy Parker on 12 Aug 2019
Latest activity Commented on by Andy Parker on 22 Aug 2019 at 11:15
I am fairly new to MATLAB and I have been given the job of developing the OO code of another programmer who has left the company (without leaving a phone number!). The software runs okay, but I need to make some changes. In order to do this, I will need a good understanding of how the code runs.
Is there a simple way of tracking the order of instantiations when OO code is run?
More generally, can anyone recommend a good book to help learning MATLAB OOP (apart from the official MATHWORKS guide - I will give that a try)?

  0 Comments

Sign in to comment.

3 Answers

Answer by Guillaume
on 21 Aug 2019 at 15:12
 Accepted Answer

With regards to "tracking the order of instantiations when OO code is run", the best way is to use the debugger with breakpoints in suitable location.
We've discussed recently a way to automatically track object instantiation and destruction but it is not something I'd recommend doing if you're new to matlab or oop in matlab.

  1 Comment

I have found that running the code step by step and making notes is good enough to give me the running information that I need for the moment. I'm getting there..

Sign in to comment.


Answer by Yogesh Khurana on 20 Aug 2019 at 11:00

Hi,
You can refer to the following links for learning material for OOPS concepts in MATLAB:
https://www.mathworks.com/help/pdf_doc/matlab/matlab_oop.pdf (it’s a very good resource for OOPS concepts to start with)
A Guide to MATLAB Object-Oriented Programming [Paperback], by Andy H. Register, is based on the old (pre-R2008a) object-oriented features of MATLAB.
Hope this helps!

  3 Comments

Thanks Yogesh,
I will check out those resources. I see that Andy Register's book is available from Abebooks.
Adam
on 21 Aug 2019 at 14:52
Make sure you understand first how old the OOP code is. If it is done in the current OOP framework then don't spend money on a book about the pre-R2008a method of doing it as it will not be useful to you at all!
The first link is by far the most useful and the one from which I learned OOP in Matlab (albeit it was a hundred or so pages shorter back in those days!!)
I found a downloadable pdf of Andy Register's book. It's quite chatty and helpful for background and introduction to concepts, but I won't rely on it for syntax.
I will wade into the matlab_oop.pdf - there's no avoiding it..

Sign in to comment.


Answer by Steven Lord
on 21 Aug 2019 at 15:28

In order to do this, I will need a good understanding of how the code runs.
Is there a simple way of tracking the order of instantiations when OO code is run?
I don't have a suggestion for the question you asked, but I do have a suggestion for your ultimate goal. You have legacy code (by the first of the modern interpretations on that Wikipedia page, "source code inherited from someone else") but it also sounds like the code may satisfy the definition from Michael Feathers, "code without tests".
If that's the case, I recommend starting by writing tests for the methods of those objects using the testing framework included in MATLAB. This may sound intimidating, but I think the script-based infrastructure shouldn't be too difficult to start with. Try looking at the Write Script-Based Unit Tests topic on the Script-Based Unit Tests page linked from the page above for an example of how to create and execute such a test.
Once you have a good collection of tests, running them as soon as you modify the class methods will increase the chances of detecting problems introduced by your modifications right away.
Function-based and class-based tests are more complicated than script-based tests but give increased functionality. The three different methods of testing can't coexist in the same test file, but as you learn more about MATLAB programming you could add function- and/or class-based test files to your suite alongside your script-based test files.

  1 Comment

The departed programmer left some test scripts which I am learning to work with. Thanks for the suggestion - when writing my own tests I will start off with script-based.

Sign in to comment.