22 ms·
C++ the Good Parts (2014)
- zerofrancisco 6y agoc++ 11 & 14 goodies: concepts, lambdas
- saagarjha 6y agoConcepts are part of the language from C++20.
- dasloop 6y agoA good source of information for what is new in C++ versions: https://www.modernescpp.com/index.php/thebigfour https://www.modernescpp.com/index.php/thebigfour That article covers the big four new features: - concepts - modules - coroutines - ranges library
- christophilus 6y agoWow. I haven’t touched C++ in maybe 18 years or so. This actually looks somewhat high level. It mentions that modules will improve compilation times. How are compilation times these days? That was one of my least favorite aspects of C++ back in the day.
- secondcoming 6y agoThey still allow for lots of sword fighting!
- pjmlp 6y agoVisual C++ point of view on the matter, https://devblogs.microsoft.com/cppblog/standard-c20-modules-support-with-msvc-in-visual-studio-2019-version-16-8/ https://devblogs.microsoft.com/cppblog/standard-c20-modules-... https://devblogs.microsoft.com/cppblog/introducing-vcperf-timetrace-for-cpp-build-time-analysis/ https://devblogs.microsoft.com/cppblog/introducing-vcperf-ti... https://devblogs.microsoft.com/cppblog/improving-code-generation-time-with-cpp-build-insights/ https://devblogs.microsoft.com/cppblog/improving-code-genera... https://devblogs.microsoft.com/cppblog/profiling-template-metaprograms-with-cpp-build-insights/ https://devblogs.microsoft.com/cppblog/profiling-template-me... https://devblogs.microsoft.com/cppblog/faster-builds-with-pch-suggestions-from-c-build-insights/ https://devblogs.microsoft.com/cppblog/faster-builds-with-pc... In general, I tend to wait less for my C++ builds than Rust ones.
- TinkersW 6y agoC++ compilers keep improving and compile times have gotten noticeably quicker for me, especially the linker step which used to take forever. It is possible to have a fast C++ build, but it still requires diligence, ie avoiding including massive headers everywhere & using lots of forward declarations etc. Many code bases don't do this so they end up with ~forever builds.
- mhh__ 6y agoOnly 20 years late, to the point where I think the design is almost outdated already (concepts can almost be done as a library if you provide the right tools a la dlang std.traits)
- ncmncm 6y agoThe good parts are also the newer parts. They were added because they make programming better. C++20 is more fun to program in than 17, which was better than 14, which was better than 11. That said, the one thing that makes C++ better than other languages is the destructor. You can see everything else added since as making destructors more useful. (I am old enough to tell you to get off my lawn. And have one.)
- cjfd 6y agoYes, agree. I think RAII is one of the greatest inventions in programming ever and basically only C++ has it. Note that it is not just about managing memory but any kind of resource like files and so on. I once made an HtmlElement class that would write the opening tag in its constructor and the closing tag in its destructor.
- ncmncm 6y agoD and Rust are the only languages that have since adopted the destructor.
- richardwhiuk 6y agoObjective C also has destructors.
- ncmncm 6y agoNot the same, and overwhelmingly less useful.
- setpatchaddress 6y agodealloc is pretty much the same thing, and it can be used in the same way. It's not "useful" in the C++ RAII sense because: - the standard library design -- every object is refcounted and any code that references the object can add it to an autorelease pool, so you can't safely predict when dealloc will be invoked - Objective C doesn't support stack-based objects
- nly 6y agoShould have a "(2014)" tag. 2 major language revisions have been released since this was recorded.
- kleiba 6y ago404 not found (scnr)
- samsaga2 6y agoThe best part by far: for(const auto& item : dummy_list) { ... } It was fucking ugly and verbose use iterators for something so basic and simple.
- tom_mellior 6y agoWhat I always found weird and verbose were all the algorithms taking begin-end iterator pairs, like: std::sort(my_container.begin(), my_container.end()); I mean, yes, in 0.1% of all cases I would want to sort something that is not an entire container, and for that it's great that this exists. But for the 99.9%, why isn't there an overload that would allow me to do: std::sort(my_container);
- makapuf 6y agoIIUC you have this using `ranges` (which itself needs concepts as implemented). With it you can even do : for (int i : ints | std::views::filter(even) | std::views::transform(square)) { std::cout << i << ' '; } notice the `for (int i:ints)` and the pipes filters. EDIT: more specifically, you can use sort on a range now (source : https://cppreference.com https://cppreference.com): ranges::sort(s);
- dgellow 6y agoWow, that pipe syntax is quite nice! Documentation here: https://en.cppreference.com/w/cpp/ranges https://en.cppreference.com/w/cpp/ranges. They are called "range adaptors" (weird naming IMHO).
- saagarjha 6y agoThey take a range and adapt it into a view, hence the name.
- innot 6y agoThe same functionality has been in boost [0] for quite a while. So, if you can't see the ugly iterators anymore, but have an outdated compiler, this is an option. [0] https://www.boost.org/doc/libs/1_72_0/libs/range/doc/html/index.html https://www.boost.org/doc/libs/1_72_0/libs/range/doc/html/in...
- MayeulC 6y agoAm I the only one thinking that C++ is becoming a real mess of features, and that it makes it hard to read a foreign codebase that uses features you are not accustomed to, unless you have 5 years of experience as a full-time C++ dev? I consider myself quite proficient at C. I wrote quite a bit of C++ from 2011 to 2014, while I was ramping up at programming. C++11 wasn't really a thing back then in my experience. The new features are really nice, but the syntax truly feels alien to me. I am now looking forward to learning Rust, which seems more cohesive in general, and less of a bag of weirdly shaped features. Meanwhile, I'll probably keep on using C++ as "C with classes" when I have to. And I feel like codebases have to pick a subset of C++ they are comfortable with to be approachable to outsiders.
- lenkite 6y agoLet's see what happens to Rust in another 10-15 years. I suspect there will be people talking about it having too many features which make it hard to read and maintain and that they look forward to migrating to the new and simple "Mend" programming language.
- xiphias2 6y agoIf you can use Rust instead of C++, look at it as a privilege: there are very important code bases that need to be maintained in C++, and modernizing the code base is still easier (and easier to automate) then moving to a new language.
- threatripper 6y agoC++ probably needs an "unsafe" keyword like Rust to isolate the non-"good parts". A few hundred compiler flags could be used to distinguish the good and non-good parts. I don't think that 5 years is enough to know all things C++; it's like a black hole in the sense that it adds features faster than you can learn how all the different parts could interact - even if you dedicate your whole life to it. Maintaining old C++ codebases will employ a lot of old developers for many many years. Your employer should not expect you to understand an old code base if you are a new developer. This would even be counter-productive since it wastes your brain power and their money. What modern C++ really needs is a rebranding. Something like "C22"/"CX"/"Z" to distinguish itself from old C++. Together with a guide on what the safe features and "unsafe"/deprecated features are the developers could get new certificates to prove that they are up to date. Companies/management could easily require that the new C++ is used and developers are actually capable. (This organizational issue is IMHO the most important part.)
- Google234 6y agoThose slides are the same style as andrei alexandrescu‘a slides.
- gridlockd 6y agoIt starts with concepts as a "good part", but they're actually terrible in their current state. Concepts are a convention, there's no insight that the compiler has into any of it, and the compiler error messages that you get are very hard to comprehend. Resist the urge to write this kind of code, at least for now. It is not worth it. Being generic isn't valuable when it slows you down because of longer compile times and because you can't make sense of some trivial error that is obfuscated by several pages of template error messages. Furthermore, even if the error messages weren't that awful, even if compile times didn't blow up, writing this kind of code is likely not a productive use of your time. More likely, it's masturbation, and C++ already has more than enough of that.
- immmmmm 6y agoNot a C++ expert, but I first encountered it 20 years ago with Windows API and it looked uglier than some dialects today. Agreed, it's not optimal when the complier spits 100k lines of error messages for a single template typo, yet it's a pretty nice language to code with. I remember talking with one of the world best HPC expert and he said that it's the most advanced language today when it comes to optimisation. Don't know if that still applies. A question while we are at it: // Am I the only one left on this planet using this style of bracketing: void foo() { cout << "brackets like that are more readable!" << endl; }
- Const-me 6y ago> he said that it's the most advanced language today when it comes to optimisation. Don't know if that still applies. I wrote quite a lot of HPC-like code lately. Can confirm. The reasons include first-party support for hardware intrinsics on all platforms (SIMD is the most important, but also scalar stuff like popcnt, pdep/pext, etc.), full control over RAM layout which allows to optimize data structures for cache friendliness, and the ecosystem of high-quality third party libraries.
- immmmmm 6y agoexactly! i did try to optimise fortran and it was quite painful for little gain.. BTW it was him: http://www.theochem.ruhr-uni-bochum.de/~legacy.akohlmey/index.html http://www.theochem.ruhr-uni-bochum.de/~legacy.akohlmey/inde...
- jandrese 6y agoThat's my preferred way of doing brackets, especially in languages where brackets are optional. I'm also a weirdo that likes default tabstops, subscribing to the philosophy that if your code is getting indented too far you might need to step back and reconsider what you're doing.
- olvy0 6y agoI use this sort of brackets too! I find them much more readable than any other style. That's just my personal view, but I find code which uses the brace in the function declaration to be disorienting when I'm reading it. My eyes are traveling around trying to see where the first line of the function is. I also write a bit of Rust and I find Rust's nagging me to use the "default" brace style annoying. IMO this is very much a personal taste issue, it depends on how someone grew up learning to read, what programming languages they grew up with, etc.
- billman 6y agoI wish I had seen this 20 years ago. I did some horrible things in c++ that I would be embarrassed to see today. It was a fun language to explore though, and I learned much from it.
- Joker_vD 6y ago20 years ago, most of those "good parts" weren't a part of C++. So nothing to be embarrassed about, one had to do with what was available at the time.
- deleted 6y ago[deleted]
- TheOtherHobbes 6y agoI would really appreciate a good and current summary of C++ best practice, including the most-favoured idioms for memory management, concurrency, structured design, and all the usual basics. This is from 2014 so although it's useful it doesn't quite qualify. The other sources I can find are either even older, or they're tutorials about very specific features with a very narrow scope.
- 0xae4f5b 6y agoThis is basically the C++ Core Guidelines.
- TillE 6y ago"Effective Modern C++" (2014) is probably still the best crash course if you're already broadly familiar with C++. There's more stuff in C++17 and 20, but the really jarring additions like move semantics were standardized earlier and therefore covered in the book. Bjarne Stroustrup's "A Tour of C++" (2018) is also frequently recommended.
- Jtsummers 6y agoJust seconding "A Tour of C++". I picked it up last year to learn modern C++ since my professional experience has solely been with older C++ standards and code bases. The book is clearly written, though sometimes very brief. It is what it calls itself, a tour. If you already know older versions of C++, it's great. If you don't know any C++ but do know how to program (more than just the basics), it's a good place to start. If you're just learning to program, it'd probably be both overwhelming (too deep too fast) and underwhelming (too shallow in critical areas for novices). It assumes you know the basics, so start with a different book and come to this one later.
- jandrese 6y agoI'm curious which parts are considered deprecated at this point. What patterns should I avoid? Certainly there must be parts that have fallen in disfavor as better solutions are introduced.
- crazypython 6y agoIs there a transcript of this talk?
- guest2143 6y agoI totally expected this to be a joke where the site was blank. I haven't worked with C++ for years, and it's nice to see there really has been some progress improving some of the C++ parts.
- bfrog 6y agoThe bad parts are the esoteric builds. X need Y built with a certain configuration on N platforms, and cross compilable from x86 to risc and arm. CMake stops helping pretty quick. Conan/Nix sort of do the trick... Wish it was more like npm or cargo at this point. Here's my deps, their versions, one command to build. I suppose vendoring everything works ala the mega Google repo?