C++ 11 Auto: How to use and avoid abuse
acodersjourney.com
C++ 11 Auto: How to use and avoid abuse
1–10 of 47 posts
Re: C++ 11 Auto: How to use and avoid abuse
#2Re: C++ 11 Auto: How to use and avoid abuse
#3Re: C++ 11 Auto: How to use and avoid abuse
#4How much of these concerns could be alleviated by an IDE that makes the types more visible?
1. The IDE cannot deduce the type within templates, and more code is moving to templates (e.g. generic lambdas in C++14)
2. Code is often read outside of IDEs: code review, search engines, etc.
3. Should C++ become a language that requires an IDE to work effectively, like Java? Probably not.
Re: C++ 11 Auto: How to use and avoid abuse
#5 auto ptr = make_shared()
Reads very nicely so I agree that if the type should be somewhere in the auto expression. That is, use auto to remove redundancy. I just wish they would have extended type deduction to lambda arguments so I could do: [](a,b){ ... }
Instead of: [](int a, int b) {...}
My understanding is that they're allowing: [](auto a, auto b) {...}
Bleh.Re: C++ 11 Auto: How to use and avoid abuse
#6The problem here is actually is an old one of failing to separate a getter from a command.
It looks like ConjureMagic is causing side effects and modifying the state of whatever class it belongs to.
This is also the reason one can't answer the question "what the heck is a?". If the "ConjureMagic" is only a getter and does not modify class state, it may probably need a better name, like "GetMaxMagicPossible". That renders an auto no longer confusing, because this name explains more than the return type. If, on the other hand this is just a command to conjure the magic and we are getting the remaining amount only to immediately pass it to the member "SetMagic" function, then there was no point in returning this value - it could be done inside the "ConjureMagic" itself.
Re: C++ 11 Auto: How to use and avoid abuse
#7How much of these concerns could be alleviated by an IDE that makes the types more visible?
That's what Herb Sutter argues in his Almost Always Auto post, but I would disagree: 1. The IDE cannot deduce the type within templates, and more code is moving to templates (e.g. generic lambdas in C++14) 2. Code is often read outside of IDEs: code review, search engines, etc. 3. Should C++ become a language that requires an IDE to work effectively, like Java? Probably not.
Really not reviewing a program inside an IDE is a poor idea in general.
Re: C++ 11 Auto: How to use and avoid abuse
#8I don't actually think the first example was that bad, modulo some context. Sometimes even knowing the type for this kind of thing isn't super important to understand what the code is doing; ala opaque types.
Re: C++ 11 Auto: How to use and avoid abuse
#9In general, I don't think C++ (or D) devs should be using deduced return types in the public interface, if at all possible.
Re: C++ 11 Auto: How to use and avoid abuse
#10Earlier quoted context omitted.
That's what Herb Sutter argues in his Almost Always Auto post, but I would disagree: 1. The IDE cannot deduce the type within templates, and more code is moving to templates (e.g. generic lambdas in C++14) 2. Code is often read outside of IDEs: code review, search engines, etc. 3. Should C++ become a language that requires an IDE to work effectively, like Java? Probably not.
I would be very surprised if someone can meaningfully review C++ templates without an IDE. Really not reviewing a program inside an IDE is a poor idea in general.