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
That said, as a professional C++ developer working in HPC, this is exciting.
Stop pretending and get back to your FORTRAN!
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.
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!
which is in the new standard
No it's not. Vendors have always been allowed to tack on GC. None of the big ones do.
-1 overrated isn't the same thing as "I disagree".
That's way to verbose. I overloaded the ;
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?
That's nothing. I overloaded eof.
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
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.
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.
It is easy to refute your argument on memory safety and auto with a single line of code:
auto obj = make_shared( arg1, arg2 );
lambda expressions can only be assigned to an auto, because the actual type is compiler defined.
auto some_callable_type = []( float f ){ return f * f; };
Currency isn't supported? What more do you want apart from: threads, mutexes, atomics, thread local storage, concurrency safe memory model, futures, promises, async tasks and thread exception transfer?
Banning random parts of the language because you don't like them? Glad I don't work for you. Fucking dinosaurs.
So you're saying it was planned to be finished in 2001? Given that the previous version is from 2003, I strongly doubt that.
The Tao of math: The numbers you can count are not the real numbers.
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!
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?
prominent compilers support it? the one supporting the most platforms, gcc, doesn't have it all yet
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.
Who cares about C++ these days?
The games industry, the financial software industry, and most companies developing niche hardware.
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.
The main purpose of "auto" is to allow for (auto p = arr.begin(); p != arr.end(); p++) {... } without worrying about the type of arr.
No, it's not. The above is written as follows in C++11:
And, of course, you can just as well use the actual element type there instead of auto.
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.
looks like the same situation as gcc, some C++ 11 things to be supported in Visual Studio 11 but other not:
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.
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.
If your compiler is doing anything different with p++ and ++p in that expression, it has a sucktastic optimizer. There's no reason it should create a copy when the value of the expression is thrown away.
Amen.
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.
The games industry
Can't speak for them ... never worked there. However ...
the financial software industry
I currently work there, and it's almost all Java or C# apart from a few legacy things in VB (shudder). The only place a subset of C++ is used is with the extremely time critical stuff that a single team uses to do arbitrage where we can host servers close enough to the exchange - and nigh on all of that would actually compile with a C compiler rather than a C++ one.
and most companies developing niche hardware
Where I used to work (doing automation), and most of my programming acquaintances still do. And it's mostly C with a little ARM assembler. C++ has never been big there because the libraries are too big and the memory use too unpredictable thanks to the amount of copying idiomatic STL code results in.
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.
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.
Plenty of legacy C++ in the finance industry. Heaps of jobs advertised want Boost, and last time I was interviewed for a position (at Bloomberg) they were interested in my C++ skills.
Not all niche hardware is small scale ARM based. A lot of it is based on Windows or Unix powered by a pretty standard desktop PC. Digital billboards, large touch screens. Things like that.
This is just Lisp with an overcomplicated syntax.
This must be one of the least insightful comments I have ever read.
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.
I'm one of those who detests operator overloading, for the simple reason that if you want a new operator behaviour, then you should define a new operator - it makes code easier to read and maintain, and avoids confusion.
But that's just my experience - you may differ.
Operator overloading is to address the ambiguity of having by-value and by-reference passing of objects being possible via different semantics in the language.
If I have a pointer and write:
ObjType* pObjRef =
then it's pretty obvious I have an object reference.
But but what does
ObjType Obj2 = Obj1;
actually mean?
C++ defines this type of transaction as always being a copy operation. But an object is a complex datatype - doing a straight copy of all it's memory doesn't necessarily give me sensible behavior. So you need operator overloading to let you enforce sensible behavior.
That you can also use it to create syntactic sugar or completely illogical behavior doesn't make it bad though. And absent a garbage collector, I'm not sure it actually makes sense to do what C# does and try and treat all object variables as references (in that when would you deallocate things?)
Huh, ok, did not know I couldn't use the ampersand in a post.
Operator overloading abuse is bad, but being able to write, for example, z*z + c instead of cplx_add(cplx_mul(z,z), c) or set - set2 instead of set.difference(set2) adds a lot to readability.
I, for one, dislike language communities driven by "Somebody can cut his finger, so let's remove all cutlery from the house" principle.
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.
I may be biased here - I first came across operator overloading a good decade and a half ago, when C++ was used in the first iterations of object-oriented databases.
It was a proper mess back then, and I fear it still is - if I want the sort of behaviour you wish to enforce, then Scala would be my language of choice - I still view C++ as C with object wrappings, templates and lots of stuff that gets in the way of efficient code.
Coming from a Lisp background, I, for one, find cplx_add(cplx_mul(z,z),c) deficient in parentheses and overburdened with commas ;-)
Try &
But that's just my experience - you may differ.
My experience is that it's beyond confusing when you need to use a mathematical ring (say), but its implementation uses operators other than * and + to implement the ring operations.
My further experience is that using your own operators is a great idea, and works extremely well right up until the point where you use a second third-party library which defines its own set of (sometimes clashing) operators. I also happen to know that no language has yet managed a sane syntax for namespace-qualifying an operator, which suggests that it may be impossible.
sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
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
How naive are you? In the real world, every language feature that gets added is a feature that all developers have to deal with, because it is used in libraries (including the standard library), affects debuggers, optimization, error handling, resource management, IDEs, etc.
Furthermore, an even bigger problem is the missed opportunity: C++ tries to be a modern systems programming language, but it fails to do a good job at that. Yet, it has enough inertia to discourage people from investing in doing something better.
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.