Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Refactor by purpose and name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

foxmuldr
Tomato Guru

USA
414 Posts

Posted - Jun 15 2016 :  10:14:40 AM  Show Profile  Reply with Quote
I've never seen the ability before, but it's something that could be beneficial. A co-worker brought up this issue in one of the applications he's working on. He finds that some developers use positives, and other developers use negatives, when creating flag variables. Some use "is active" (positive) and others use "is inactive" (negative). It's one of his biggest complaints.

So, suppose I have a negative variable form in an application I've inherited. The variable is called "isInactive". It's used about 200 places, so it's not easily manually refactored. But, I would really like to switch the variable around to be the positive form "isActive" so that it goes along with the rest of the application's design.

Would it be possible to add an ability to VAX which would find all references of that variable (as it does today), and then to go the step further and flip each usage's logic around to the opposite condition? In that way, a type of "refactoring by purpose and name" rather than just "refactoring by name," could be achieved?

For example:

bool isInactive;

    if (isInactive)
        // Do something


The above would become:

bool isActive;

    if (!isActive)
        // Do something


Best regards,
Rick C. Hodgin

Edited by - foxmuldr on Jun 15 2016 10:31:21 AM

feline
Whole Tomato Software

United Kingdom
19021 Posts

Posted - Jun 15 2016 :  7:44:43 PM  Show Profile  Reply with Quote
We have considered a related, simpler idea, inverting a specific if statement:

case=27848

I have put a note onto the case about this extension of the idea.

Here, it is the open ended nature of this that concerns me. If we can assume that the variable is only ever checked for true / false, you still need to think about:

IsInactive == false
false == IsInactive
IsInactive <> false

all of which are handlable. But what if it is used inside a much more complex if statement, where there are several conditions chained together?

What about other checks? What if this is used to control a while loop? Something like this, you need to have a lot of confidence in your automated code edits, and an awareness of possible edge cases.

zen is the art of being at one with the two'ness
Go to Top of Page

foxmuldr
Tomato Guru

USA
414 Posts

Posted - Jun 15 2016 :  8:28:37 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

We have considered a related, simpler idea, inverting a specific if statement:

case=27848

I have put a note onto the case about this extension of the idea.

Here, it is the open ended nature of this that concerns me. If we can assume that the variable is only ever checked for true / false, you still need to think about:

IsInactive == false
false == IsInactive
IsInactive <> false

all of which are handlable. But what if it is used inside a much more complex if statement, where there are several conditions chained together?

What about other checks? What if this is used to control a while loop? Something like this, you need to have a lot of confidence in your automated code edits, and an awareness of possible edge cases.



My suggestion would be to assign a confidence level on each entry, and as with the Shift+Alt+R refactor display today with its checkmarks to choose or not choose the refactor on that item, extend the purpose refactor form to allow full source code editing on each line so the user can override the auto-suggested fixup.

You can also place the confidence level (either something generic like high, medium, low confidence, or an actual value) into a sortable column so they can be at the top or bottom of the list.

It might also be desirable to have a "Print" option to get a hard copy of the proposed list of changes for offline review, as sometimes it's easier to take a pencil and go through each one individually and mark it off, and then go and fixup the two or three that were invalid.

And if you really want to get fancy, you could add a feedback feature which allows the user to send back the original source code line, info VAX has about the variable type, what its proposed change was, and what it actually wound up being as per the user's edits, so that you can look for common patterns and extend your algorithm to handle those use cases.

Best regards,
Rick C. Hodgin
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19021 Posts

Posted - Jun 23 2016 :  1:55:20 PM  Show Profile  Reply with Quote
All sensible ideas, but also showing just how complex this could get, and how messy it might get. For now, we don't even have the basic "invert an if statement" feature up and running. Some form of confidence level is reasonable, and I already made a note of that idea when noting this on the case.

Certainly something to consider, but I am not sure if or when we might try this.

zen is the art of being at one with the two'ness
Go to Top of Page

foxmuldr
Tomato Guru

USA
414 Posts

Posted - Jun 24 2016 :  12:01:26 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

All sensible ideas, but also showing just how complex this could get, and how messy it might get. For now, we don't even have the basic "invert an if statement" feature up and running. Some form of confidence level is reasonable, and I already made a note of that idea when noting this on the case.

Certainly something to consider, but I am not sure if or when we might try this.



As I say, I've never seen it before. It would be a nice feature.

Best regards,
Rick C. Hodgin
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000