You must be registered to post a reply. Click here to register.
T O P I C R E V I E W
Dan Forever
Posted - May 10 2018 : 04:22:40 AM 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();
5 L A T E S T R E P L I E S (Newest First)
feline
Posted - May 12 2018 : 09:44:31 AM 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.
Mordachai
Posted - May 11 2018 : 4:55:59 PM 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.
Zeblote
Posted - May 11 2018 : 4:12:56 PM
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.
accord
Posted - May 10 2018 : 7:38:53 PM We are considering to add this as a refactoring command before long:
case=79735
Mordachai
Posted - May 10 2018 : 11:32:04 AM 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).