Sutter: C++11 kicks old-school coding into 21st century
Language officially infused with Java-like multi-core support
There's a new C++ in town: C++11 has been approved and published by international standards chiefs.
C++11 is the first major revision to one of the world's most popular programming languages in 13 years. The update will position apps using the language for coding for the next two decades. C++11 was published by the ISO on Tuesday following ratification of the standard in August.
One of the biggest changes in the spec helps make C++ a little more Java-ier: the introduction of a standardised multi-core-friendly memory model that Java has had since 2005.
The standardised memory model is intended to save developers from having to build or pick their own libraries in order to achieve concurrency in C++11 applications. The idea is to introduce greater consistency in the way apps are built when running on the kind of multi-core processor chips that power servers in data centres and can be found in the smartphones running in your hand.
Sutter: Modern C++ code is as clean and safe as code written other modern languages.
C++ steward Herb Sutter, convener of the ISO/ANSI C++ Standards committee since 2002, reckons C++11 makes the case for "traditional" languages in a world of managed platforms.
Concurrency has been one of Sutter's crusades. In 2005 Sutter told devs that the free lunch of single-core was over and that C++ had to go concurrent.
Sutter's employer, Microsoft, took the managed platforms route last decade with the introduction of .NET and the Common Language Infrastructure, which were part of Microsoft's answer to Sun Microsystems' then-new Java. Sutter has been Microsoft's lead designer of C++/CLI and extensions to Visual C++ for parallel programming.
Java daddy James Gosling, meanwhile, is reported to have said that Java is C++ without the guns, knives or clubs.
Sutter said that C++11 incorporates many of the best features of managed languages like Java, which he reckoned emphasise programmer convenience at the expense of express power and performance through features like always-on garbage collection.
"'Traditional' programming using native languages like C++ – which emphasize expressive power and a pay-as-you-go philosophy of avoiding performance overheads unless features are actually used in the programme – never really went away," Sutter said.
"Now with C++11's improvements that incorporate many of the best features of managed languages, modern C++ code is as clean and safe as code written other modern languages, as well as fast, with performance by default and full access to the underlying system whenever you need it."
When we spoke to Sutter earlier this year, he said garbage collection would likely be proposed for the successor to C++11: it was in the C++11 mix but cut due to a lack of time.
Other changes in C++11, meanwhile, include lambda functions, move semantics and variadic templates: this all makes programming an easier and less profane experience and helps C++ apps tap the power of the underlying hardware they are running on.
Speaking to The Reg, Sutter reckoned C++11 feels like a fresh language, with all the power and descriptiveness C++ fans know and love. ®
of the death of C++ have been greatly exaggerated. Well written C++ is a thing of beauty and a joy forever.
+1,000,000 (all instantiated into the same reused block, of course)
Garbage collection is pure, distilled and concentrated evil for interactive or real-time systems. The best it can offer you is a statistical value for event latency, but with such a wide deviation that you need to run the software on a grossly overspecified platform in order to make sure that even if your event occurs during a GC run, you'll still get to handle it in time.
And I still haven't come across a good argument for why you'd need GC, let alone one that would make me give up "Resource Acquisition Is Initialisation". Most arguments for GC grossly overestimate the amount of direct dynamic allocation a typical C++ application programmer does, and never fully take into account the deferred cost of cleaning up later.
Fifteen years later, you can *still* tell that an application was written in Java. It's got that "sticky" feeling, like a watching a machine with a slipping gear, as that wonderful GC jumps in at the most inopportune moments. It's fine for quickly building client/server applications that can hide behind network latency, but you'd need your head examined to write something like a real-time embedded operating system in Ja--- oh, never mind...
On C++11 itself, while the memory model work is great, very few will notice it, and while that does sum up most of the new features, there are some standouts: As someone who had to teach C++ many years ago, I welcome the new meaning of the "auto" keyword with open arms: it sure beats typing "std::map<std::string, std::map<std::string,std::vector<std::string> > >::const_iterator" . On that note, the official recognition of what the two characters ">>" together should mean when found inside a template declaration is a small, but also very welcome, addition.
Other high-points for efficiency are the introduction of move construction and rvalue references, both of which remove the spurious extra objects that can occur when passing by value. Sure, they're mostly of interest to library authors, but they've been added in a way that often won't require rewrite of client code.
Before complaining, I'd suggest a read of the FAQ (http://www2.research.att.com/~bs/C++0xFAQ.html) might be in order. Of course, if you're already convinced that Java or C are the world's best languages, there's not a lot that would convince one otherwise.
Missing the point
90% of programmers don't know what they are doing to that level of detail.
A lot of programmers have learnt on the job and never covered these areas. Hell most of us don't even have time to.
If OS programmers employed by the likes of MS - who would be by no means stupid - still leave gaping holes what hope is there for the average code monkey?
Safer all round but much less efficient and elegant to have the language plug most of the holes for you.
Downside of course is that ultimately it's less safe than a programmer whole truly knows what they are doing at a low level.