Biggest Changes In C++11 (and Why You Should Care)
Esther Schindler writes "It's been 13 years since the first iteration of the C++ language. Danny Kalev, a former member of the C++ standards committee, explains how the programming language has been improved and how it can help you write better code."
I could've sworn I was using it before then.. perhaps it was all just a bad dream?
The article is probably referring to the first finished C++ ISO standard, 14882:1998. Hardly the "first iteration" of the language.
Yeah but this one goes to eleven!
Would love to use these features in the new C++, but unfortunately none of the major compilers support the new for-syntax, in class initialization, deleting members and explicit specification of base class methods.
Also I totally don't understand why enum class no longer casts to ints... it totally makes using binary flags impossible unless I revert back to using the old style enums. But then I need to do the ugly namespace myenums { enum myenum { foo = 4, bar = 8 ... }; } hack which makes nesting inside classes impossible -_-
I really like that they added new stuff to the language but ...
Have they *removed* anything at all from it? That's the only way I could get interested in that language again.
This is news for nerds. Stuff that matters. I thought /. abandoned this stuff ages ago...
Slashdot - News for Nerds, Stuff that Matters, in ISO-8859-1 Has just realised that beta makes this signature redundant
C++ goes all the way to 11. It's one louder than other languages.
C++0x is C++11. C++0x was a placeholder name until they actually knew what year it would be finalised.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
If the "alternative syntax" from PHP were allowed, the language could even become legible. What I see is still a write-only language.
Nae king! Nae laird! Nae yurrupiean pressedent! We willna be fooled again!
http://en.wikipedia.org/wiki/C%2B%2B0x#Features_to_be_removed_or_deprecated
Your comment caught some flack, but I couldn't help but make a similar observation as I read the spec. It seems that they are adding a lot of stuff to C++ that exists in C# (lambda expressions, delegated constructors, automatic deduction, initialization syntax, a dedicated null keyword, etc).
Of course, they added a bunch of stuff that's also NOT in C# (since it's not necessary in a high-level language like C#), but I am glad that they are revamping C++ to incorporate some higher-level functions. Now we just have to wait for compilers to start adopting the new spec...
You know, like how Clash at Demonhead and Mega Man 2 took place in "200X!"
And it looks like they missed their worst-case deadline by 2 years!
I love had back in the day C++ advocate sneered at ADA due to that fact that ADA was "designed by committee". Now C++ is the ultimate example of a design by committee language. And that committee is huge.
Puzzle Daze is now my job
It's been awhile since I've had to do any C++, so maybe I'm just missing something, but it seems like either there's a lot of retarded functionality here, or there's a lot of TFA which introduces a feature, even motivates it, but doesn't actually explain what the new version looks like. For example, with "Rvalue References":
Ok, first, what? I thought standard library string implementations were supposed to be efficient, and include some sort of copy-on-write semantics, which would (I would hope) make the above a shuffle-pointer-around instruction instead of a copy-data-around instruction.
Second, here's the newer, better syntax:
Regarding the first comment, no, I really don't, unless the point is that this is what the code for "moving" would look like if implemented in older versions of C++. But also:
Ok, cool... But where is this used in the "moveswapstr" example? Does this make the "naiveswap" example automagically faster? Or is there some other syntax? It doesn't really say:
The C++11 Standard Library uses move semantics extensively. Many algorithms and containers are now move-optimized.
...right... Still, unless I actually know what this means, it's useless.
It looks like there's a lot of good stuff here, and the article is decently organized, but the actual writing leaves me balanced between "Did I miss something?" like the above, and enough confusion that I'm actually confident the author screwed up. For example:
Great! Awesome! Of course, this arguably should've been there to begin with, and the 'auto' in front of these variables is still annoying, coming from dynamically-typed languages. But hey, maybe I can write this:
Instead of:
It's almost like C++ wanted to deliberately discourage abstraction by making it as obnoxious as possible to use constructs like the above. Anyway, that's what I expected the article to say, but instead, it says this:
Don't thank God, thank a doctor!
The saddest part about this whole C++0x ordeal is that they're still just playing catch-up to C#.
True. In particular, C++ is light years behind C# in patent FUD. And C++ hasn't even started work on requirements for a 100MB "managed environment" for users to install before running their apps. Nor have C++ developers chosen a monkey species after which to name its 2nd-class-citizen cross-platform implementation.
GCC has it mostly implemented (the new concurrency features remain MIA along with a few other bits) already, including the variadic templates the GP mentions.
http://gcc.gnu.org/projects/cxx0x.html
upon the advice of my lawyer, i have no sig at this time
What is the big fuss about getting a garbage collector anyway? Why does it even matter? Good C++ code shouldn't need a garbage collector. If memory was allocated within an object then the destructor should be taking care of it. And with shard_ptr (which people should start using) it's taken care of within there anyway. Is this wanted so everyone can start coding sloppy C++ and forget about the delete calls? I suppose for those using some 3rd party library that behaves poorly and is totally out of your control it could be nice to stop that from leaking all over. Still, it should have been done right in the first place.
I suppose there might be some argument for preventing excessive memory fragmentation. Is there some other benefit to having one?
Fear is the mind killer.
In fact, Windows Vista and 7 already come with .NET pre-installed, so there's no need to download anything to run a .NET app.
Cause I really enjoyed the latest .net Framework 3.5 and 4 security updates that was nearly 400 MB... Thank you MS!
It's /. after all :/
Cause I really enjoyed the latest .net Framework 3.5 and 4 security updates that was nearly 400 MB... Thank you MS!
I also enjoyed the way it spent over an hour pre-compiling assemblies during the update. Granted, it was on an old machine, but it still would have been ridiculously long on a modern one.
Would love to use these features in the new C++,...
Why? What is it about these new features that will make your job easier, your code more reliable, and easier to be maintained? Or do you just want to use those features because they're "new" - for C++ that is?
As a long time C++ guy (Borland C++ days), I look at some of these features and think "so what?" (Lambda functions, please.) I'll probably never use them. IMHO the last truly useful feature that C++ added was Templates which lead to the STL and made my life much easier... I stopped reading at this point... .
Let me stop you right there for a second. Proper utilization of lambdas and closures pretty much make a lot of design patterns (template, strategy, visitor, for example) unnecessary in many contexts. This obviously will have an impact in how you write/use templates. Furthermore, lambdas and closures help with shrinking class hierarchies even further than delegation alone.
Yes, we had functors before, but now you neither need to define functors classes/structs defining 'operator()', nor have to invoke new on them. That is substantially less typing to achieve the same without loss of generality, semantics or performance. We know from industrial evidence across multiple programming languages (or you should know) that this type of facility, when used properly, reduce complexity and the introduction of new bugs. It helps you focus more on the algorithms at hand without worrying about the boiler-plate that it is needed for its setup.
. This might look trivial in contrite pedagogical examples such as the one found in the wiki section of C++0x#lambdas found here. However, with real algorithms, one typically have to employ more than one functor. That's where the brevity of lambda expressions pay.
What is happening to you is that you have never done actual work with a language that supports lambdas. And as such, you cannot even imagine how these thing alone (when used appropriately) make code cleaner, and more bug-free.
In the end, you will know this until you use them in work/real-life scenarios. Until then you only have an opinion based on subjective feelings, not from-the-trenches facts. Give them a HONEST, laborious, nontrivial try, if not in C++ at least in some other, non-trivial work on another programming language, and try the same algorithms without them.
After the exercise, you might still think they are useless (and I would still think you are wrong). But at least you will have a hands-on basis for your opinion (as opposed than just puffed air.)
But... until then, I honestly don't think there is anything really worthwhile I could do in c++ that I can't do in c
RAII. That's a tremendously important idiom that simply cannot be expressed in C.
When I depend on the compiler to write part of the code for me, I'm going to get mediocre performance from a one-size-fits-all model without any real option to do anything about it.
One can always write "C-like" code in C++ but the result will probably exhibit worse performance. Compilers are actually quite smart. It's often programmers being "helpful" to the compiler that screw things up. A classic example is using unsigned integers for loop counters. No, the compiler actually doesn't care that it can "see" the loop counter will never be less than zero but it absolutely does care that it might wrap around due to overflow.
...in 1995 when I saw there was nothing of interest in it. If I want to do system level stuff, I'll use C. If I want to do object programming, I'll use Java and/or Go. I don't see the need for a language that mixes both except as a confusing and hard to maintain broth. Do you pass your food through a mixer before you eat it ?
Non-Linux Penguins ?
RAII is not important to me and does not implement anything I can't do myself, with extremely fine grained control. To "express" this functionality, I check my allocations, I check my return codes and states, I make sure I provide same, I only do new things based on the known state of things I've already done, and I set up state-testing, abort-capable monitors for operations that might conceivably go open-ended. I try really, really hard to never use other people's code for which I don't have control of the source. Then I test the living heck out of things. And this all leads to release-level programs that don't die by exception in the first place, therefore eliminating the need for a program level mechanism to "save" me due to exceptions.
You know, I hear that a lot, but looking at the code the compilers actually generate... it's not evidently the case. Concrete example: I am presently in the middle of a very large image processing project which uses the GCC compiler for objc and c. I have had many occasions to look at the generated code for both idioms, and it is *terrible*. Constant reuse of single registers, as if the CPU only *had* one or two usable registers; thrashing variables on and off the stack, failure to optimize simple shifts and divides of integers... the kindest thing I can say about the GCC compiler is that the code works. It *certainly* doesn't produce good or "smart" code. Writing in assembly, I could run rings around it without ever breaking a sweat.
Recently, I had occasion to dissemble and patch a bug Apple had left around in the launchd code for Leopard (10.5.) Even if you assume I'm using GCC poorly, one would think that Apple might be a little better at it, yes? Well, the same thing was strongly evident there: register resuse / register wasting, stack thrashing, basically failure to optimize and failure to utilize.
So while I'll certainly grant you that theoretically speaking, compilers could do a good job than a competent assembly programmer, it's not clear, at all, that they actually do a better job than a competent assembly programmer. The evidence I've seen recently, after many years of compiler development, is entirely the other way.
I've fallen off your lawn, and I can't get up.
You know, I hear that a lot, but looking at the code the compilers actually generate... it's not evidently the case. Concrete example: I am presently in the middle of a very large image processing project which uses the GCC compiler for objc and c.
gcc is not a terribly good optimizing compiler, particularly for things like image processing. Try the same code with the Intel compiler or PGI.
Constant reuse of single registers, as if the CPU only *had* one or two usable registers
There's a register-pressure tradeoff being made here. Reusing registers like this lowers the register pressure of the code, reducing spilling. The other extreme is to round-robin the register allocator which allows more scheduling freedom at the cost of inducing more spilling.
thrashing variables on and off the stack
Register allocation is a hard problem. It's NP-complete. Can one "eyeball" some asm in specific cases that will outperform the compiler? Sure. But over a large amount of code, a good compiler will win and will save the programmer time.