Wholesome C++11

Preamble

What is good about the C++11.

Comments

I have been using predominately C++11 for quite a while in a commercial setting.
I’ll use
https://blog.smartbear.com/c-plus-plus/the-biggest-changes-in-c11-and-why-you-should-care/
as a starting point to remind me of some of the key features.

auto
This is great, but requires a change of mindset in how you do things. Gone are
FruitT f = …
in is
auto fruit = …
which make it more readable.
Auto I think is the best thing introduced as it does improve readability and allows less experienced C++ guys to get to grips with the language without worrying too much about the detail, however still providing compiler level type checking. Definitely a win for me.

nullptr
Well it’s about time! least said.

lambdas
Definitely better than bind, and can replace bind completely. No more writing tedious functor objects.
Downside is specification didn’t got far enough and allow templated lambdas. And the syntax isn’t nice. It is clean and terse, but quite hard to remember as most of the time you are writing procedural code.

Uniform initialisation
I have tried to use it and mostly its OK, but still not comfortable with it in all scenarios. Generally speaking its the way to go, but using it everywhere doesn’t always cut it.

Deleted and default functions
Definite winner.

Rvalue references/std::move
A winner, but with caveats.  Its all about speeding up the compiled code. It does allow nice things like returning big objects via value rather than have to return them as modified parameters.

auto_ptr, new pointer classes
Death of it is great! And new pointer classes are definitely a win win.

What C++11 cannot give us
The main issue I have with C++ usage isn’t the language itself. It is how its used. Code needs to be easily testable via unit tests. Code structure isn’t mandated by the standard. However later versions add extensions for contract based programming. But even then I feel that trying to keep all bits of code independently testable is the best way forward.

Conclusion

C++11 is a winner, but the standard may not save you if you don’t code nice.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.