Thursday, February 28, 2013

C++ 2011

Coming off a recent project that used a small portion of the
new 2011 C++ standard, I've recently been delving into some of the gems of the
new specification, and I have to say that my "old-dog" skeptical eyes
have been re-opened.

One of the things I have always loved about the C++ language (and
it's procedural predecessor, "C") is the relative
"smallness" of the language:
It is a lean, simple and well defined tool that once learned,
is exceptionally powerful. Given these "small, simple and powerful"
attributes, one can be lulled into the conclusion that not much more is
necessary... nor desired. But looking at
the latest C++ specification (specifically, ISO/IEC 14882:2011), it is clear
that many good things were indeed needed - we've just been used to living without them. This is akin to the phenomena of "deodorant
soap": We got along without it for
a long time... we just didn't realize how badly things were stinking until we had an alternative: Life is sweeter with it, than without it.

So what's so sweet about C++ 2011? I've provided a short list of new features below. I'll name them first (just to wet your appetite), then
follow up with some specifics in future posts:

Automatic Type Deduction. So obvious, you'll wonder why it took so long.

Defaulted Functions. This allows the compiler handle a lot of trivial stuff we used to write by hand,... over and over... and over.

The long missing "nullptr". This one deserves a few bars of the Hallelujah Chorus (can you hear the chorus in your minds ear?). At long last... we have an unambiguous, core language construct with which to initialize a pointer to a "null" (empty) value, without getting it confused with an integer, or anything else! Do I hear an "Amen" brothers and sisters?

Delegating Constructors. I have a feeling most of us have been coding our way around the lack of this ability for so long, that we forgot it stinks (again, the deodorant metaphor). Now, you can leverage code used in one constructor from another constructor of the same class. Wow! Makes sense, right?

RValue References. These open up some enormous opportunities for run time efficiency that many of us might have been "writing off" for a long time. Cool stuff.

New Additions to the Standard C++ Library. Support for threading, smart pointers, and new algorithms. For me, the 800 pound gorilla is the threading and smart pointer support. How many of us have been home-brewing our own solutions for portable threading and re-inventing smart pointer classes, at the expense of productivity? We just may have been liberated.

In future posts, I'll take each one of these new language features (and a few more) and delve into them with more detail, including examples, starting with those I personally find to be the coolest. Stay tuned!

- Dave Arndt

Copyright (C) 2013 by Orion Development Corporation. All Rights Reserved.