Perhaps the most common single question about C++11 is: When should we use
auto to declare local variables?
Here's a current set of responses on Programmers.StackExchange. Enjoy.
Does auto make C++ code harder to understand?
I saw a conference by Herb Sutter where he encourages every C++ programmer to use
I had to read C# code some time ago where
varwas extensively used and the code was very hard to understand -- every time
varwas used I had to check the return type of the right side. Sometimes more than once, because I forgot the type of the variable after a while!
I know the compiler knows the type and I don’t have to write it, but it is widely accepted that we should write code for programmers, not for compilers.
I also know that is more easy to write:auto x = GetX();
someWeirdTemplate<someOtherVeryLongNameType, ...>::someOtherLongType x = GetX();
But this is written only once and the
GetX()return type is checked many times to understand what type
This made me wonder -- does
automake C++ code harder to understand?
Add a CommentComments are closed.