Archive

Posts Tagged ‘C++11’

The Lost Decade?

April 10, 2012 8 comments

I think you’ll be hard pressed to find many knowledgeable C++ programmers who won’t admit that managed languages provide higher per-programmer productivity than native languages (because they’re easier to learn, have bigger libraries, and are not as “picky“). Likewise, I think you won’t find many “reasonable” managed language advocates who won’t admit that native language programs are more efficient (smaller and faster for a given solution) than their managed language counterparts. Having said that, take a look at this chart:

According to Herb Sutter, efficiency has(will) usurped(usurp) productivity as the dominating cost factor for software-intensive products in this decade (battery life in mobile devices, power consumption in the data center). Agree?

If you’re interested in watching the video and/or downloading Herb’s slides, here’s the link: C++ and Beyond 2011: Herb Sutter – Why C++?“.

Categories: C++, C++11 Tags: , , , ,

A Dearth Of Libraries

February 27, 2012 Leave a comment

In Herb Sutter’s talk at GoingNative 2012, he opined that the biggest weakness of C++11 is its dearth of libraries; which causes programmers to waste lots of time ($$$) writing their own code to implement mundane functionality like XML parsing, cryptography, networking/sockets, thread-safe containers (<- I’ve had to spend quite a bit of time doing this!), serialization, etc.

Using language and library specification page counts, Herb started out by showing the progressive growth of C and C++ over time:

Next, Herb presented this eye-popping chart of relative library size for C++11, .NET, and Java:

Yes, that’s C++11 down in those tiny blue boxes. WTF! Note that the core language specifications on the left side of the chart are roughly the same size.

To address the issue, Herb proposed the formation of a an open-source Portable C++ Libraries (PCL) organization with the following guiding principles:

Herb also addressed the issue of how the PCL would interact with the C++ standards committee with this chart:

Basically, the PCL would serve as a front end vetter and integrator of library submittals in order to unburden the committee from the responsibility and allow it to concentrate more on tricky core language features (concepts, modules, static if, etc). The C++ committee would serve as the final fine-grained scrutinizer and approver of library additions to the language. In practice, libraries like poco and Qt could be shipped with every standards-compliant C++ compiler in the future.

I think Herb’s idea is a good one and I hope it blossoms into the real deal. How about you? What do you think?

Broken Books

February 19, 2012 4 comments

With the addition of features like auto, initializer lists, lambdas, and smart pointers, a lot of C++98 programming idioms and guidance have become obsolete now that C++11 is here. Thus, as Herb Sutter said at GoingNative 2012, a boatload of code examples in the best C++ books are now “broken“.

As a result, new and revamped versions of the books will take awhile to become available. Here’s Herb’s “estimated time of arrival” for several stalwart books:

In the meantime, you can feast your eyes on, and feed the left side of your brain with, these links:

Do you know of any other good links to add to this post?

Concurrency Support

February 3, 2012 Leave a comment

Assuming that I remain a lowly, banana-eating programmer and I don’t catch the wanna-be-uh-manager-supervisor-director-executive fever, I’m excited about the new features and library additions provided in the C++11 standard.

Specifically, I’m thrilled by the support for “dangerousmulti-threaded programming that C++11 serves up.

For more info on the what, why, and how of these features and library additions, check out Scott Meyers’ pre-book training package, Anthony Williams’ new book, and Bjarne’s C++11 FAQ page.

One Chart Summary

October 4, 2011 Leave a comment

While flipping through Herb Sutter’s “C++ And Beyond” keynote speech charts, I stumbled upon this fabulous one chart summary of all (almost all?) the new features available in C++11.

Pretty intimidating, but cool, eh?

Final, Not Virtual

September 7, 0201 Leave a comment

When writing C++ code, I used to have the habit of tagging every destructor in every class I wrote as “virtual“. I knew that doing so added memory overhead to each object of a class (for storing a pointer to the vtable), but I did it “just in case” I decided to use a class as a base in the future. I was afraid that If I didn’t designate a class dtor as “virtual” from the get go, I might forget to label it as such if I decided later on I needed to use the class as a base.

I have actually made the above mentioned “inheriting-from-a-class-that-doesn’t-have-a-virtual-dtor” mistake several times before – only to discover my faux pas at runtime during unit testing. However, since C++11 added the “final” keyword to the core language to explicitly prevent unintended class derivation (and/or function overriding),  I’ve stopped tagging all my dtors as “virtual“. I now tag all of my newly written classes as “final” from the start. With this new habit, if I later decide to use a “final” class as a base class, my compiler pal will diligently scold me that I can’t inherit from a “final” class. Subsequently, when I remove the “final” tag, it always occurs to me to also change the dtor to “virtual“.

#include <iostream>

class ValueType final {
public:
  ~ValueType() = default;
};

class BaseType {
public:
  virtual ~BaseType() = default;
};

int main() {
  using namespace std;

  cout << " sizeof ValueType = "
       << sizeof(ValueType) << " bytes" << endl
       << " sizeof BaseType = "
       << sizeof(BaseType) << " bytes" << endl;
}

Value Type Size

Categories: C++11 Tags: ,