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 option - Expand "auto" to actual type
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Dan Forever
Junior Member

10 Posts

Posted - May 10 2018 :  04:22:40 AM  Show Profile  Reply with Quote
A refactor option that will convert something like this:
auto* myVar = MyFunction();


into this:
MyNamespace::MyClassType< int >* myVar = MyFunction();


where "MyNamespace::MyClassType< int >" is the type of the return value from MyFunction();

Mordachai
Tomato Guru

USA
224 Posts

Posted - May 10 2018 :  11:32:04 AM  Show Profile  Reply with Quote
Dan - if you mouse over myVar it will tell you that it is a MyNamespace::MyClassType<int>*.

By leaving your code as an `auto` it means you can update MyFunction()'s return type without having to then run around and update callers (or not as much). It also avoids possible logic errors where you're not asking for a conversion from the actual return type to your explicitly declared type.

You might still want this for some things - but you appear to going against the flow of modern coding standards (and the reasons they were introduced).
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - May 10 2018 :  7:38:53 PM  Show Profile  Reply with Quote
We are considering to add this as a refactoring command before long:

case=79735
Go to Top of Page

Zeblote
Tomato Guru

183 Posts

Posted - May 11 2018 :  4:12:56 PM  Show Profile  Reply with Quote
quote:
Originally posted by Mordachai

Dan - if you mouse over myVar it will tell you that it is a MyNamespace::MyClassType<int>*.

By leaving your code as an `auto` it means you can update MyFunction()'s return type without having to then run around and update callers (or not as much). It also avoids possible logic errors where you're not asking for a conversion from the actual return type to your explicitly declared type.

You might still want this for some things - but you appear to going against the flow of modern coding standards (and the reasons they were introduced).



There are definitely reasons to not use auto - for one, it makes it much easier to see what is going on at a glance, and you actually *reduce* errors by stopping the compile if you change the return type of something without caring.

Many large projects (for example, Unreal Engine) completely forbid the usage of auto unless it's an unreadable template type.
Go to Top of Page

Mordachai
Tomato Guru

USA
224 Posts

Posted - May 11 2018 :  4:55:59 PM  Show Profile  Reply with Quote
It is a problem. I prefer the clarity of having the type spelled out sometimes - but I also like the automatic update if I change the interface slightly, or choose a different interface with similar semantics.

There is no 100% winning - just a case by case "what makes sense here" - and I don't know about you - but I find that annoying and somewhat unsatisfactory.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - May 12 2018 :  09:44:31 AM  Show Profile  Reply with Quote
One use case that has been suggested for this refactoring is when you type auto, fully intending to have it expanded by VA once you have written the line, since it is faster and easier to type auto and expand it than it is to type the full type.

Personally I have always liked clear full types, but especially when working with templates they can get very long to write out.

zen is the art of being at one with the two'ness
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