News for hackers. Stuff that matters.
Re:The C++14 Standard: What You Need to Know by RogerL on Wednesday September 17, 2014 @01:29PM (#8331181)
Then start with Herb Sutter, because that is exactly his advice at the latest CppCon.
Re:The C++14 Standard: What You Need to Know by jobu on Wednesday September 17, 2014 @03:06PM (#8331777)
Yes, and he's said that in a few blog posts as well:

http://herbsutter.com/2013/06/07/gotw-92-solution-auto-varia...

http://herbsutter.com/2013/06/07/gotw-93-auto-variables-part...

http://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-...

He has some good points, but his perspective seems to be biased by a professional focus on writing libraries and more general-purpose code. He's also brilliant and can remember things like this:

  const int&  cir = val;
  auto        h   = cir;
  //The type of h is int.
It's difficult to make generic rules for how to use C++ (because it's used for everything from adware to nuclear reactors), but I can say that Herb's AAA (Almost Always Auto) rule would not fly on any development team I've ever worked with.
Re:The C++14 Standard: What You Need to Know by swift on Wednesday September 17, 2014 @03:48PM (#8332009)
The type of h isn't so hard to understand, there. |auto| gives you a value; if you want a reference, use |auto&|. This rule actually makes |auto| more readable: you always know if you're looking at a reference or not.

Probably you expected |auto| to behave like |decltype()|, C++11's other form of type deduction, which gives you the actual type of an expression. C++14 adds |decltype(auto)|, which lets you declare local variables using this behavior if you want it.

I'm not sure whether I'd apply Herb's AAA rule quite as broadly as he suggests, but I think it's broadly right, because far too often in C++ we write a type twice on the same line, which is just redundant. I vastly prefer |auto val = new MyClass;| to |MyClass val = new MyClass;|, and similarly |auto casted = static_cast<MyType>(uncasted);| is completely readable without typing writing "MyType" a second time. C++ programmers are a conservative lot, but I expect using |auto| at least in those cases to be pretty mainstream within a few years.