MATLAB Answers

Nils G
6

Feature Request: Refactoring tool

Asked by Nils G
on 21 Nov 2016
Latest activity Commented on by per isakson
on 8 Apr 2019
I would like to have a real refactoring tool for MATLAB like the one e.g. in PyCharm. At the moment I'm using Grep if I'm renaming a Class/Method/Function.

  0 Comments

Sign in to comment.

5 Answers

Answer by Grivault
on 17 Oct 2018

I agree, the lack of this refactoring capability is making Matlab IDE quite outdated face to other IDEs... As it seems to me impossible to develop Matlab with another IDE it makes Matlab also non-competitive and less attractive face to other languages (python, java, C# etc...) Missing syntactic coloration is already from another age, but since it's intrinsic to Matlab we can accept it. Refactoring though is the minima nowadays.

  0 Comments

Sign in to comment.


Answer by Adam
on 2 Apr 2019

This is still such a huge frustration all the way into R2019a. Even things that should be so simple can take on epic proportions when it comes to simple changes.
In one of my latest classes I didn't think ahead far enough and named some public functions things like
getData(...)
getScaledData(...)
getTrainingData(...)
Now, of course, a few weeks later I am incorporating a 2nd type of data that I didn't expect originally. So now I have to rename these functions to something more specific than just 'Data'. But they are public functions so I now have to search the whole repository with a Find All. This is not so bad for getTrainingData(...), I don't have many occurences of this, but I have numerous classes with a getData(...) function and loads of places that call it. The class/object of the call gives them their scope so the functions don't need more specific names often.
Except now when I come to have to do a rename and I have to sift through all those cases to make sure I only change those related to the class I am editing.
My design may not be great in terms of having these functions where they are, but isn't that the whole point of refactoring? You don't need to do perfect upfront design, you evolve it as appropriate!
This is one of the most basic tasks of refactoring too. I have no idea how easy or difficult is is for Matlab to link these in an interpreted language, but other languages seem to do it and even Matlab itself I have noticed has improved a lot in terms of its resolution if I 'Go to definition' on a function and it manages to take me to the relevant class.

  3 Comments

Luke M
on 5 Apr 2019
That's a perfect example of why this is needed. I'm not sure how to get it onto MATLAB's radar as a sorely needed feature.
I did find recently that if you use CTRL-SHIFT-F, you can search for text in you whole workspace or in a folder (either recursively or not). It's not refactoring per-se, you can't use it to find/replace, but it is a huge improvement. I don't know when the feature was added, I came across it by accident in 2017b, but it's worth mentioning here.
Adam
on 8 Apr 2019
Yeah, Ctrl + Shift + F is the method I've always used (it has been around as long as I remember). It helps, but still getting a list of 100+ matches when only 4 of them are related to the specific occurence I want to change makes refactoring a slow risky business!

Sign in to comment.


Answer by Frank
on 8 Oct 2018

Dear Don,
Nils asked about refactoring and not how to rename a local variable. The lack of support for refactoring within Matlab is quite annoying.
-Frank

  0 Comments

Sign in to comment.


Answer by Don Zheng
on 7 Dec 2016

Hi Nils,
Please find the tutorial below for code refactoring in MATLAB Editor:
-Don

  1 Comment

Luke M
on 7 Aug 2018
I know this is a fairly old question, but I haven't found anything more recent. I think what Nils is looking for is a tool to refactor a project when renaming, as they said, a Class, Method or Function. The tutorial presented is great when working in a single file, but what about when working on a project with many files?

Sign in to comment.


Answer by Keith Nguyen on 9 Nov 2018

This is true. If I want to rename a function (to give it an easy-to-understand name instead of test(ptcle1,ptcle2). I'll break my program. Is there a way to rename the function across all files in the same project/folder/workspace?
Other features such as: - Changing function signature also change it across all files. - Moving lines up and down using shortcut. - Syntax highlighting.

  0 Comments

Sign in to comment.