Stroustrup Reveals What's New In C++ 11
snydeq writes "Bjarne Stroustrup discusses the latest version of C++, which, although not a major overhaul, offers many small upgrades to appeal to different areas of development. From the interview: 'I like the way move semantics will simplify the way we return large data structures from functions and improve the performance of standard-library types, such as string and vector. People in high-performance areas will appreciate the massive increase in the power of constant expressions (constexpr). Users of the standard library (and some GUI libraries) will probably find lambda expressions the most prominent feature. Everybody will use smaller new features, such as auto (deduce a variable's type from its initializer) and the range-for loop, to simplify code.'"
I mean, it's not, but it makes it sound like C++11 is a minor update. Lambdas, auto, concurrency, are these minor updates? There's a lot of interesting stuff in C++11!
Wood Shavings!
- Godai
Unfortunately I code in java these days.. chances that oracle will see the light? :-)
Probable impossibilities are to be preferred to improbable possibilities.
Aristotele
Seriously? This is months old! You know how old this is?
It's a collection of new C++ features, and prominent compilers have already added support for it. Getting C++ compiler vendors off their butts to implement new features takes freakin' forever, but I can already play with lambdas, auto, and variadic templates - at least.
That said, as a professional C++ developer working in HPC, this is exciting.
Small interview, not anything new is added. Trolls will enjoy the old Java versus C++ thing again.
Seriously, a big disappointment.
Have you heard about SoylentNews?
S-expressions, continuations, hygenic macros...
Many developers are still using C++ as "C with classes".
Comment removed based on user account deletion
In some ways, a lot of what is being added to C++ makes me think of Scala, just less readable.
While the additions and extensions certainly make things more interesting and potentially more powerful/easier for the *individual* programmer, I look forward to seeing what sort of interesting train wrecks happen when larger teams try to make use of these features. I certainly hope the debuggers are being updated to be useful when someone's written a template that uses a #define'd macro to specify a closure that is passed through an anonymous function, etc.
This strikes me as the next generation's 'multi-threading' -- where almost every programmer claims they can handle multi-threaded programming, but very few actually do it well. Particularly in teams when interactions require coordination. Going to take a whole new round of winnowing the wheat from the chaff when it comes to finding developers who can actually use these features well without driving their coworkers insane.
Optional Garbage Collection, which is in the new standard, is a horrible idea. You cannot depend on it, as it is not guaranteed, and it will slow programs which do not need it, as well as potentially break low-level operations on memory. I have no idea what they were thinking when they allowed that in, but it is a very dangerous "feature."
Great Intellect...
I shall now make two predictions:
1) Hordes of comments are about to appear that denigrate C++.
2) 95% of these commenters have never written any C++ code more sophisticated than
Welll, now.
You see, being a C++ GOD, I have actually overloaded 'Hello World!' and made it into an operator! And with my overload, you just implemented an operating system!
That's way to verbose. I overloaded the ;
Yeah, everyone knows 'using namespace' is for chumps.
I don't think you'll see a lot of people flaming C++, there just aren't that many people that care one way or the other anymore.
I think some of the new features look nice but mainstream use has been shifting away from C++ for a while and I'm not sure I see these new features drawing many back...
"There is more worth loving than we have strength to love." - Brian Jay Stanley
FTA
I expect to see the first complete C++11 compiler sometime after I see the apocalypse.
Oh right... I guess that would be December 2012, wouldn't it? :)
Seriously... while a lot of compilers implement some of the features, I really don't think there's a hope in hell of seeing any real progression to adopting the standard. With C, the standard developed around what many compilers were already doing... ditto with the original C++ spec. But C++11 describes a standard that absolutely nobody has ever got anywhere close to, so I don't imagine that there's going to be a lot of drive to adopt it.
File under 'M' for 'Manic ranting'
WTF?
Hey you,
I've written big apps in C++ and can tell you: C++ SUCKS!! It's a piece of shit language with a very crappy garbage collector, a baroque, undecidable syntax, no end of karma, and a community that revels in BDSM programming. With an emphasis on the M.
So there.
I nearly thought you were serious, until you started complaining about C++'s garbage collector...
That's nothing. I overloaded eof.
a video of Stroustrup presenting C++11 style: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style
a paper by Stroustrup describing C++11 for software infrastructure: http://www.computer.org/portal/web/computingnow/0212/whatsnew/computer-r?src=cnhome-v1
C++ SUCKS!! It's a piece of shit language with a very crappy garbage collector
If you are making extensive use of the C++ garbage collector and it isn't working very well, I can understand your frustration :D
Probable impossibilities are to be preferred to improbable possibilities.
Aristotele
The new version of C++ is a decade behind schedule, and consists mostly of marginal features. Memory safety hasn't improved. Concurrency isn't really supported in the language; all that's really been done is to nail down some of the semantic issues that matter when multiple threads are executing on superscalar processors. There are lots of new features only useful to people writing templates, which are a terrible programming environment. "auto" is useful (I wanted to call it "let", but there was objection to a new short keyword), mainly because the type definitions of iterators are so bulky. The main purpose of "auto" is to allow for (auto p = arr.begin(); p != arr.end(); p++) {... } without worrying about the type of arr. As long as arr is an iterable collection, that should work.
This still doesn't prevent buffer overflows, but at least the most concise way to iterate over an array is reasonably safe. (Not totally safe; modifying a collection over which you are iterating breaks the memory model.) Over the next few decades, the number of buffer overflow bugs might decrease slightly.
It's an improvement, but not one that was worth waiting a decade for.
I guarantee you will quickly come to hate the new "narrowing" errors, for example any time int converts to float inside initializer curlies, or double to float. As a language feature, this lies firmly in the category of wanking.
That said, my code is all full of lambdas now, thankyou. On the other hand, lambda syntax is uglier than sin. While a lambda can do anything a lexically scoped nested function can, it is not pretty. Now obviously, there is no reason not to support proper lexically scoped nested functions, as GCC already does. Arguing that they are now unnecessary because of lambdas is, again, wanking. The practical fallout is that when you move a lambda-style helper function to global scope or to member status, you have a bunch of editing to do, to remove the ugly auto/lambda bits.
Another big disappointment is, nothing was done to address the good features C99 has that C++ does not. Designated initializers and variable size array parameters, to name two. Wanking again.
On the whole, there is too much wanking going on in the C++ stewardship process. Guys, you need to remember, C++ does not exist only as a means of compiling the STL.
Have you got your LWN subscription yet?
I was amused by the comment "If that incr(0) were allowed either some temporary that nobody ever saw would be incremented or - far worse - the value of 0 would become 1. The latter sounds silly, but there was actually a bug like that in early Fortran compilers that set aside a memory location to hold the value 0. "
Back then, I wrote Fortran subroutines which took computed dimension arrays by declaring the arrays with crazy bounds, numbers I hoped would never be used as constants, and then "assigning" the real bounds to the "constants".
Those were the good old days.
Actually makes a lot of sense. I normally pretty much ignored the committee, since most of their work seemed to involve things (template madness) that I strictly ban from my teams' projects anyway. The influence of C# is obvious and largely welcome; I'm less thrilled about seeing more boost (a lot of banned code there too, though most of it here looks okay) and attempts to bolt on functional paradigms. That falls under the same heading as garbage collection, as in Apple's misbegotten attempt with Objective-C++.
Still no viable replacement for the preprocessor, but a fair amount of stuff that looks useful, and some to be avoided.
I think he either forgot his LSD today, or took too much. Not sure which yet.
Support the EFF and Creative Commons. The war is coming, and they're supporting you...
Since the advent of 64-bit pointers, the garbage collector in all of my C/C++ compilers has been working great.
I overloaded your mom.
Support the EFF and Creative Commons. The war is coming, and they're supporting you...
I've written big apps in C++ and can tell you: C++ SUCKS!!
Based on your comment about the C++ garbage collector, I assume your big C++ app was something like:
for (int i=0; i<10; i++)
std::cout << "Hello, World." << std::endl;
std::cout << "You had me at the first Hello!" << std::endl;
Who cares about C++ these days?
Time to move on to something modern
Well, the thing is that this is typical C++ brain damage. If you criticize that there is no garbage collector, you get some bullshit involving std::shared_ptr. I mantain that most C++ programmers think that that rotten POS is actually a garbage collector. If you then say, well, whatever, "C++ has a rotten POS of a garbage collector", then, of course, it turns out C++ has no garbage collector. Go figure.
Brain damage all around.
I watched a few of the "Gone Native" webcasts on the C++ extensions, and it's crazy what they're doing with the language. Are the features useful? Yes, but they're taking a complex language and slapping on yet more functionality. Some new C++ code syntax doesn't even *look* like C++ anymore it's so different. Not everyone is a C++ guru and the language is bad enough supporting so many different paths to the same implementation outcomes. This is just going to make staffing, testing, training, and code review that much worse trying to juggle yet another barrel-full of C++ "improvements".
They need to just start from scratch and create a limited subset of features that doesn't pretend to be C and doesn't lug around all of the past mistakes in the standard, and call it C+++.
I swear to God...I swear to God! That is NOT how you treat your human!
All of the issues with C++ are easily dealt with simply by coding in C and checking back in to see what C++ is like in another ten years.
I always thought if you're going to go to all the trouble of smartpointers, you might as well just use garbage collection and make your life easier.
Don't leave garbage lying around. Clean up after yourself.
Probably the last thing preventing it from being truly safe and useful in shared libraries across implementations.
How many years has it been?
and these new features?
There is no right to feel safe thru security vaudeville at the expense of everyone's freedom, privacy and tax money.
Garbage collectors only manage memory. Smart pointers, on the other hand, can manage any kind of resource - whatever you release in your destructor.
That's why languages like Java and C# still need stuff like Closeable and IDisposable, and syntactic sugar for them to avoid writing try/finally ladders. Whereas in C++, resource management has always been done right, and memory is treated as just another kind of resource.
Comment removed based on user account deletion
I gave up on C++ years ago. It has really become a 'geek cred' language with a constantly changing 'right' way an aesthetic, perfect for figuring out if a fellow geek is from the same snapshot of teaching you came from, but that is about it. It has become overly complex with redundant language features that one needs to keep relearning in order to understand other people's code.. and of course with complexity comes the ability to show off your knowledge through doing things in 'clever' ways.
Good for showing off.. bad for getting actual work done, esp for projects that last more then a year or two.
C++ started out as a small set of focused, simple enhancements to C. It didn't pretend to be a great new language, just provide workarounds for some of C's most annoying problems. It was nice and I started using back then, about 25 years ago.
Now C++ has turned into a disaster, a bloated pig of a language, with features added left and right, incoherently, in order to try to catch up with other languages. But if you want speed, you still have to get rid of all the layers of abstraction that C++ offers and write it in plain C (or a C-like subset). And C++'s attempts at module systems, separate compilation, and garbage collection are still much worse than pretty much any other language.
Thats the sort of stuff I heard about 15 years ago, a little late, those guys should have been hard at a new release the day java got popular and got $100s of millions of dollars in developer seeding in the 90s
Come on intel, give us a microcode C# & java VM accelerator in the cpu.
Liberty freedom are no1, not dicks in suits.
Yeah, right.
In one corner we have memory, which is 99% of the "resources" needed to be managed, and for which deallocation cannot fail.
In the other we have everything else, which is not many, and for which deallocation can fail.
Simple example, open a file, write to it, let the dtor flush and close. If flushing fails, you won't know, because dtors can't return anything, and exceptions in dtors is a big no-no (because, incidentally, there's no GC to free the stuff). That's _wrong_. If you want to do it right, you end up with the same mess.
This all-resource-should-be-treated-the-same-way stuff, while cute, is a big joke. Smart pointers are a lousy GC scheme that does memory badly (ref counting is inefficient, especially on MP systems, and cannot handle cycles) and does non-memory badly too (because closing these can fail, and dtors can't handle that).
Stroustrup? Really? Couldn't they find anyone more knowledgeable about C++? They must be really scraping the bottom of the barrel :-)
Doesn't mean all that much if the compiler vendors dont implement all these great features.
Visual C++ (the compiler I have to use for a certain project due to C++ ABI compatibility issues with existing code and a better compiler on Windows than GCC IMO) doesn't support any of the interesting stuff like "Delegating Constructors", "Inheriting Constructors", "Initializer Lists", "Range-based for-loop", "constexpr" and "Non-static data member initializers".
Even the next version is little better on supporting the nice bits of C++11 :(
Instead Microsoft spent a lot of effort adding all kinds of useless new compiler crap to support their WinRT junk (which to me seems like the answer to a question nobody asked)
In one corner we have memory, which is 99% of the "resources" needed to be managed
Go ahead, count the number of calls to "Close" and "Dispose" in a real world C# or Java app. Then get back to us with some solid number for that 99% claim.
Simple example, open a file, write to it, let the dtor flush and close. If flushing fails, you won't know, because dtors can't return anything, and exceptions in dtors is a big no-no (because, incidentally, there's no GC to free the stuff). That's _wrong_.
Suppose you're right, and you detect that flush failed during close. What are you going to do?
Suppose furthermore that you have an exception in flight, and you've just had flush fail in your finally-block (assuming C#/Java). What are you going to do now?
If you want exception safety, you need RAII, period. If you have RAII, you might as well use it for memory.
Smart pointers are a lousy GC scheme that does memory badly (ref counting is inefficient, especially on MP systems, and cannot handle cycles)
Those claims that refcounting is inefficient are old, but somehow they only show up in synthetic tests. In real world apps, something written in C++ is invariably faster and more responsive than alternatives written in managed languages. That's precisely why C++ is still used far more widely for desktop apps, and is used almost exclusively anywhere perf really matters (like games).
And there's weak_ptr for cycles.
Except, of course, in case of circular references. Oh, and before you mention weak references (to be totally honest, I am not even sure if there is a standard weak reference in C++), I'll mention that very few C++ programmers know what they are. The syntax of C++ is so crowded that the language is only used for low level stuff where the extra 5% performance boost is a big deal. I am not sure if CUDA programming can only be done in C++, but I think that if one absolutely needs CUDA, then he is already doing some low-level stuff.
Any guest worker system is indistinguishable from indentured servitude.
(Not arguing with your broad point that these new addirions to C++ will be useful.)
Goto is no way sufficient for modern programming. You also need some way to manipulate whatever passes for the (effectively stack) constructs that allow nested parameters and locals. And you need some way to hide the bulky extra code (as in text macros and such).
I got bit on this when I should have known better, back in '97 or so -- using a Fujitsu CoBOL, forgot that the old CoBOL PERFORM was kind of like the old BASIC GOSUB. Found myself trying to use recursive calls in some UI code, and the variables I was expecting to be local to the procedures were, of course, global, and my fancy UI screen would keep blowing up.
I'd have had to implement effective stacks all over that code to keep it from blowing up. Gave up and reverted to the older, much harder to understand UI.
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
Oh yeah? I modded your mom flamebait!
Support the EFF and Creative Commons. The war is coming, and they're supporting you...
I was playing around with a factoring sieve the other day when I realized just how much my choice of language colored the algorithm I used.
If you use the same algorithm across all the languages, it prejudices your results. If you use a different algorithm for each, you end up comparing apples and oranges.
Sure, if you use the stuff in your language that requires overhead, the overhead will be there.
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.
Oh, and before you mention weak references (to be totally honest, I am not even sure if there is a standard weak reference in C++)
std::weak_ptr in C++11. Been there for 7 years now (originally as std::tr1::weak_ptr), and for a few years before that in Boost.
I'll mention that very few C++ programmers know what they are.
That's the problem with those programmers, not the language. C++ is powerful and fast by design; that, unfortunately, also makes it complex by design. It's not a language for everyone, and Java and C# certainly have their very large niche. But C++ is a very powerful tool when used right.
The syntax of C++ is so crowded that the language is only used for low level stuff where the extra 5% performance boost is a big deal.
That's emphatically not true. I've repeated it several times already in this thread, and I'll repeat it again: most desktop software today is written in C++. Heck, even a fair bit of OS X software is written mostly in C++, especially if you look at the size of it (MS Office, Photoshop). The reason for that is that perf boost (relative to Java/C#) is more like 20% for common tasks; but, more importantly, there is a marked responsiveness improvement due to lack of GC. And responsiveness is some really subtle stuff - it's not quite the same as "fast", but it's very sensitive to stutter on the order of tens of ms (a delay over 100ms is already noticeable by the user).
You can write good UI software in managed languages, but then you need libraries that are themselves written in native code, at least rendering and input layer. Otherwise you end up with a clumsy pig like Swing.
Yeah that has helped, look at Win2008 Server and Exchange 2010.
What bloody hungry hippos, either too many coders re implementing shit, or fucked If i know.
But interfaces/guis dont need C++, they would work as well in C#.
Judging by MS's C++ API, stop using long named objects, and 12 function calls to achieve one objective.
Hey, windows2000 uses less ram than android on a $60 phone. Why not just use win2000-64bit as a datacenter OS in VMs, running non-MS open sourced linux apps.
Boot Win2008Svr, and it uses more ram than 4 linux distros running at once in 4 VMs.
Liberty freedom are no1, not dicks in suits.
http://www.youtube.com/watch?v=r5whVyDoLLc&feature=related
Java is now somewhat bloated, but has not reached C++'s level of fat rolls and pustulence.
Where are we going and why are we in a handbasket?
I'll mention that very few C++ programmers know what they are.
That's the problem with those programmers, not the language. C++ is powerful and fast by design;
Not really. Most Java programmers know about the weak references in Java. And in Java they are less necessary than they are in C++ (because the C++ gc model steaming from smart pointers is based on reference counts). If a necessary tool goes underused in a certain context, then it is the problem with how the context is presented to its audience -- not with the audience.
But C++ is a very powerful tool when used right.
Any tool is only as powerful as it is useful. It is not reasonable to judge tools only by the peak performance achieved by its most committed users.
The reason for that is that perf boost (relative to Java/C#) is more like 20% for common tasks;
And I posted a fairly simple benchmark which shows otherwise.
there is a marked responsiveness improvement due to lack of GC.
Only for a certain class of problems. Btw, I would say that mark-and-sweep is a type of gc -- not that it is gc. Reference count is also a gc method. But that's a semantic argument. And I am more than willing to admit that it is a matter of opinion.
You can write good UI software in managed languages
All application languages are managed.... by the operating system.
Otherwise you end up with a clumsy pig like Swing.
Swing is only clumsy because it attempts cross-platform functionality (which necessitates that it supports only the least common denominator of features). It's not clumsy for any kind of inherent performance design issues in the Java language.
Any guest worker system is indistinguishable from indentured servitude.
This is just Lisp with an overcomplicated syntax.
I think C++ 11 may be falling into the trap of trying to be all things to all programmers. Certainly developments in C# and Java had something to do with some of these improvements. But, at what point can one say that a system has become too complicated to quickly reason with? Has C++ reached that point?
That said, certainly these changes are welcome improvements for existing C++ developers who want easier ways to reduce complexity of their code.
memcpy means undefined behavior if your data type is not a POD.
Oh, and "many feel" is weasel-wordy to the extreme. Who, exactly, feels this and what are their reasons? Are their reasons sound and well-founded?
Pretty cool stuff. What are the best resources for learning about the most modern implementation of C++?
I am not sure if CUDA programming can only be done in C++, but I think that if one absolutely needs CUDA, then he is already doing some low-level stuff.
CUDA Fortran is where it's at for hard-core number-crunching. See e.g. http://www.pgroup.com/resources/cudafortran.htm
Every end has half a stick.
Still i'd rather have a language with features I don't want than a language that is lacking features I do want.
note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
I can write a FORTH in the old Motorola M6800 assembler. Once I have the FORTH, it's not that far to a rudimentary web browser, although the address space limitations will prove a source of frustration.
Implementing FORTH on the 6809 is a bit more fun. High level constructs, more registers, access to the stack that does not have to tunnel through arcane sequences of pushes/pops/swaps.
Implementing FORTH on the 68000 is much more interesting, because it has enough registers to access parameters/locals, persistent allocation areas, thread locals and globals, etc. It's not just syntactic sugar when you don't have to waste half of your code fighting the botlenecks.
Goto is not enough.
Computer memory is just fancy paper, CPUs just fancy pens with fancy erasers; the 'net is just a fancy backyard fence.