7 ms·
C++11 use in Chromium
- jesuslop 12y agoMove semantics banned until revision.
- nhaehnle 12y agoI would be curious about the rationale behind this. Move semantics are a clear win in many situations, and I don't see any obvious pitfalls associated with them. I am curious especially about mere std::move; I'm aware that using rvalue references directly can be a bit confusing initially, and it makes sense to reduce their use.
- kps 12y agostd::move is a library function, and some Chrome targets don't have C++11-conformant libraries yet.
- reubenmorais 12y agomove is just return static_cast<T&&>(value); Library support for std::move is not the reason it's disallowed. (If it is, that's just silly and someone should create a discussion thread).
- gtremper 12y agoIts more than that. You can't put move-only types into std:: containers if the target doesn't have a C++11 support. There are many other pitfalls like this that are hard to notice until you try it on a pre-C++11 target.
- reubenmorais 12y agoSupport for move semantics in library containers is a better reason for disallowing it, I'm just pointing out that std::move (and std::forward) is the simplest part of the puzzle.
- gtremper 12y agoWell, if the simplest part of the puzzle isn't implemented, then I doubt the rest of it is.
- kentonv 12y agoLast I heard the C++ style arbiters at Google (a handful of very-senior engineers who dictate how everyone else at the company should write code) felt that rvalue references were too hard to understand and would therefore lead to more problems than they solve. Admittedly my knowledge is a couple years old, but the rule specified here of "you can only use them with explicit permission from the C++ style arbiters; maybe we'll reconsider later" seems consistent with that reasoning. I'm glad I don't follow their rules anymore. rvalue references are incredibly useful in making ownership transfers explicit, and although they may sound confusing on first description, once you get the hang of it, they are easy to reason about.
- ajross 12y agoThe problem is you're demanding that the entire coding population of a large company "get the hang of it" or else be confused by their tools. That is a proposition with non-zero cost, so it needs to be weight against the derived benefit. And IMHO for move semantics, that benefit is pretty low. The overwhelming number of allocation bugs with C++ code are treated very well by RAII already. Move semantics tend to be best used in library code that implements some kind of dynamic runtime. And let's be honest: that's stuff that (1) tends to be done by experts already and (2) has been done successfully and robustly for decades in C anyway. Larry and Guido didn't need move semantics...
- kentonv 12y ago> The problem is you're demanding that the entire coding population of a large company "get the hang of it" or else be confused by their tools. The fact of life in C++ is that you have to grasp a number of not-entirely-intuitive concepts before you can be effective with it. Rvalue references are not particularly hard compared to many of the others. Consider how much time newbies spend wrapping their head around pointers -- something that experienced C++ programmers have absolutely no trouble with. The only reason we're holding rvalue references to a higher standard than any other C++ feature is because they're new, which means that even people who have been coding in C++ for decades suddenly find that there is a language construct they don't immediately understand. Not having felt this way for a very long time, they conclude that this particular construct must be much more complicated than everything else, when in fact it's not. > The overwhelming number of allocation bugs with C++ code are treated very well by RAII already. Move semantics make it vastly easier to use RAII in the first place. Without them, RAII does not play nicely with transferring ownership over a call or a return. You can use reference-counted smart pointers, but they are slow (require atomic ops). You can try to emulate move semantics via documentation and conventions, but this is error-prone. Clean ownership transfers have always been a sore spot in C++ prior to rvalue references. I don't know about you, but the introduction of move semantics into my style completely transformed my code for the better.
- heycam 12y agoThe equivalent rules for Mozilla code: https://developer.mozilla.org/en-US/docs/Using_CXX_in_Mozilla_code https://developer.mozilla.org/en-US/docs/Using_CXX_in_Mozill...
- jcmakon 12y agoVisual Studio limiting progress as always..
- pjmlp 12y agoVisual Studio 2014 is already much better. http://blogs.msdn.com/b/vcblog/archive/2014/08/21/c-11-14-features-in-visual-studio-14-ctp3.aspx http://blogs.msdn.com/b/vcblog/archive/2014/08/21/c-11-14-fe... Last time I checked, outside most C++ compilers were still catching up with C++11. There are more C++ compilers out there than just clang and gcc. Even those aren't 100% compliant at library level, if I am not mistaken.
- Suro 12y agoActually Clang is fully C++14 compliant, and already has some C++1z features, and gcc only need a few more patches.
- jonstewart 12y agoIt must have been a while since you last checked. Many of the features listed here as banned because of lack of VisualStudio support have been available in gcc and clang for years.
- pjmlp 12y agoGCC 4.9.1, was released on 2014-07-16. Still quite a few rows with N. https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#... I was only wrong about clang. So my point still holds for gcc, and it doesn't change the fact, that there are more compilers out there than the triad clang, gcc, vc++.
- deleted 12y ago[deleted]
- BruceIV 12y agoNot everyone has the most recent versions of the compilers, either; my institution is still working on the upgrade path from Ubuntu 12.04 LTS to 14.04 LTS, so I had to get a modern gcc manually compiled to get proper C++11 support, because nothing in the 12.04 package manager had full support.
- femngi 12y agoStuff like this makes me really regret being a C++ developer. Companies and projects are adopting new features at a glacial pace and yet the programming world is still moving forward and it feels like despite the best efforts of the committee and the compiler teams C++ is doomed to continue being a 'legacy language' as companies either continue migrating to C# or sticking with C++98.
- CountSessine 12y agoInstead of living with regret, why not ask yourself what kind of software you want to be writing and what kind of problems you want to be solving? Some software should be migrated to C# and Java. On the other hand, when it comes to runtime performance, memory footprint, and compiler and runtime availability, nothing matches (or even comes close yet) to C/C++.
- pjmlp 12y agoAda? D? Turbo Pascal? Modula-2?... Some of C and C++ advantages come from having 30 years of compiler optimizations, while compiler vendors stoped caring about implementations for other languages. I am big on C++, but as a language geek, I am looking forward to .NET Native release, and see how far it can take C# in this language X vs language Y discussions.
- CountSessine 12y agoAda? D? Turbo Pascal? Modula-2?... All great languages, but try finding a D compiler for a Blackfin chip, or something similarly esoteric. C++ just goes more places where you would want it to go. Some of C and C++ advantages come from having 30 years of compiler optimizations, while compiler vendors stoped caring about implementations for other languages. Certainly - with a clean slate in 2014, you'd design something else - something that would make static analysis easier and static constraints possible. Basically, something like Rust. But C++11 is still pretty cool. I am big on C++, but as a language geek, I am looking forward to .NET Native release, and see how far it can take C# in this language X vs language Y discussions. I had no idea C# was 'going native'. I guess we've come full circle, what with this and news of Android L moving to ahead-of-time-compiled 'java'. Still, I have absolutely no interest in C#.
- xpaulbettsx 12y agoIs there a great guide to C++11 as a language? Typing "Learn C++11" into Google always results in information mixed with legacy C++
- femngi 12y agoThe definitive introduction to C++11 is probably 'C++ Primer 5th edition'. It covers stuff other than the new features but everything is described as it should be done in C++11/14.
- ekm2 12y agoBjarne Stroustrup's The C++ Programming Language(4th Edition) is updated for C++11.
- pjmlp 12y agoThe new book from Bjarne "Tour of C++".
- krylon 12y agoThanks for the suggestion. I am not a C++ programmer[1], but I try to keep an open mind about other languages. I loved reading Design And Evolution of C++, Bjarne has a very nice writing style. [1] Last year, I spent about a week doing maintenance on what you could call a legacy C++ application at customer site (I work as a sysadmin at a process engineering company). It was strangely fun (lucky for me, the application was quite well-written and I could easily find my way around the code).