7 ms·
Ask HN: How to refresh on modern features of C++?
I first learned C++ 14 years ago and have only used it in a non-trivial fashion on one or two short projects since then.
Today, reading an article on popular C++ myths [1], I now realized there are a TON of things I didn't realize modern C++ can do now. auto, unique_ptr, for_each, and range-for loops were new to me. I'm not 100% certain if all of these were recent additions to the language.
What are some things I can do to brush up on the modern features of C++?
[1] https://isocpp.org/blog/2014/12/myths-1
- tjr 12y agoI've not read it, but the author's other books have been well-regarded for years: http://www.amazon.com/Effective-Modern-Specific-Ways-Improve/dp/1491903996/ http://www.amazon.com/Effective-Modern-Specific-Ways-Improve...
- boost_ 12y agoI've read it already, the final retail version, not the early draft and its pretty awesome (like all his other books). IMO its better than the Bjarne Stroustrup book (which i've read too), but any of the two is fine to learn modern C++ features.
- wmkn 12y agoI agree. Effective C++ was/is the guide for C++98 - Effective Modern C++ is the guide for C++11.
- overgard 12y agoI have read it. Would highly recommend it. Most other guides just go over the neat things, but this one also goes over all the potential pitfalls and things to watch out for (and it's C++ -- there's always something to watch out for :))
- azmenthe 12y agoI would like to read this book but the O'Reilly website eBook + Print combo deal is not available until next year.. Does anyone know how I can order both and get the early access ebook now and then the print book when it's ready?
- optymizer 12y agoThe first few chapters of The C++ Programming Language by Bjarne Stroustrup 4th edition go through a tour of C++11 that will quickly show you how to use modern C++ techniques. The rest of the book can be used as a reference to learn more about specific features.
- inglor 12y agoDefinitely this one, not only does he explains modern techniques he explains the rationale behind them, why they were added and how to use them without getting shot in the foot - emphasizing values over references and avoiding `delete`s.
- jerv 12y agoHerb Sutter, one of the most prolific C++ experts out there, recently gave a talk on Modern C++ [1]. In the beginning of his talk, he states that every C++ developer should read a "Tour of C++" [2] by Bjarne Stroustrup, the original designer of C++. I recently read it and it's great. The book has less than 200p, but still covers the most important parts of C++11, albeit not in great detail (the reader is pointed to "The C++ Programming Language" by the same author for that). Read it! And watch the youtube video in [1]. [1] https://www.youtube.com/watch?v=xnqTKD8uD64 https://www.youtube.com/watch?v=xnqTKD8uD64 [2] http://www.amazon.com/Tour-In-Depth-Series-Bjarne-Stroustrup/dp/0321958314 http://www.amazon.com/Tour-In-Depth-Series-Bjarne-Stroustrup...
- ghantila 12y agocppreference.com is a good resource too. It's updated frequently. http://en.cppreference.com/w/ http://en.cppreference.com/w/
- lallysingh 12y agoI can't stand that site. I try to use the old SGI stl reference whenever I can.
- throwawayaway 12y agoit's a great site, but it's jarring at first. the sgi stl reference doesn't have a lot of c++11 in it.
- forrestthewoods 12y agowhoa really? To me cppreference is the single best example of code documentation I've ever used. Clean, easy to search, thorough but skimmable listing of interfaces, great example code, modifiable example code, provides necessary information not part of function declarations (iterator invalidation rules). I'm surprised you prefer the far more bare bones SGI version.
- cubbimew 12y agoHow is the reference for a library abandoned over 15 years ago even relevant? (other than when researching history)
- thepumpkin1979 12y agoSimilar story here, I played with C++ back in 1998 and then again in 2007. After reading these two books it definitely changed the way I see and work with C++, I fell in love with it. So reading old code-bases is very common, you still need to understand the old C++ anyway: Professional C++, Wrox, Jan 2005 Then to get yourself up to speed with C++11 and C++14: Professional C++ 3rd Edition - Wrox, Sept 2014
- vowelless 12y agoWatch the videos from GoingNative and CppCon. Speakers like Bjarne and Herb constantly talk about "whats new in Modern C++". Watch Andrei's talks for sure! http://channel9.msdn.com/Events/GoingNative/GoingNative-2012 http://channel9.msdn.com/Events/GoingNative/GoingNative-2012 http://channel9.msdn.com/Events/GoingNative/2013 http://channel9.msdn.com/Events/GoingNative/2013 https://www.youtube.com/user/CppCon https://www.youtube.com/user/CppCon
- shmerl 12y agoJust read the new edition of C++ Programming language by Bjarne Stroustrup ;) Some things are hard to come by in any shorter sources. And at times you have to dig into the standard. An example of rather obscure thing in C++ which changed in C++11 (sequencing): http://en.cppreference.com/w/cpp/language/eval_order http://en.cppreference.com/w/cpp/language/eval_order And another thing which can be pretty confusing without carefully reading the standard. Copy elision vs move constructors... See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n324... § 12.8 (Copying and moving class objects), #32 - 33
- jmount 12y agoNot to be disrespectful- but I want to learn more about C++ from anybody but Stroustrup. His writing (to me at least) always has the aspect of "nothing is wrong, and every compromise was picked correctly." I'd much rather read somebody like Meyers who will actually warn you away from some mal-features. And C++ is so large you really want a useful editorial view to any teaching.
- shmerl 12y agoFrom such books I liked "Thinking in C++" which is a good intro, but there is no up to date version and it's missing details.
- shawn-butler 12y agoScott's style is also to be quasi-entertaining. In my opinion he uses this style of pointing out the dark corners not to inform but to make the reader/listener feel a part of the "epic struggle" / journey dialogue. It seems to work quite well to sell books, consulting and as a pedagogical conceit and is worth emulating. Bjarne has never had such pretense and his writing also reflects his personal style. And he will tell you quite honestly that some distasteful aspects exist because C++ was a language created to be used (backwards compatibility is a feature, adding keywords/syntax only when necessary, etc) not that "nothing is wrong." Any rational discussion of programming languages is one of relative merits, applicability to specific problems, and personal prefs, rather than one of absolute truths.
- sedeki 12y agoHow about C++ Primer 5th edition?
- wglb 12y agoThe Scott Meyers books on Effective C++ are excellent.
- gdy 12y agoDon't like Scott Meyer's books, but this pdf has chance to be good: http://www.artima.com/shop/overview_of_the_new_cpp http://www.artima.com/shop/overview_of_the_new_cpp
- Stubb 12y agoI'm in the same boat and working through "A Tour of C++" by Stroustrup. It highlights the new features you're talking about with concise examples but doesn't flesh out the details. So you'll know that there's an often-better way to do certain things using the new language features. You'll need another reference for assistance with the details, often Stack Overflow examples suffice. "Effective Modern C++" goes more into the details and is next on my queue. I've done a bunch of Ruby, Java, and some Lisp programming since my last stint with C++. It feels like a whole new language.
- throwawayaway 12y agoWell at the risk of stating the obvious, there's a lot of armchair programmer style "read this", "watch this" instruction here. It's much better to do something concrete. Go and do a trivial project in it, cppreference.com and cplusplus.com have c++11 tags on the new features. I'm sure you've had ideas recently and I'm sure the project is less trivial than you thought! I think looking at language features first is "a solution looking for a problem" attitude.
- to3m 12y agoPeople who learn C++ this way tend to miss stuff out, I think - there are a lot of thing that you can just muddle your way though without really understanding. I'm sure there are some people that think this will be OK; after all, lots of people say you don't really have to understand templates unless you're writing a library (and so on). But I don't think it will be OK. There was very little in C++98 (that I knew well, at the time) that it was OK not to know; unless you knew all of it, pretty much, you couldn't really use any of it safely. (This is how Scott Meyers makes his living.) I can't imagine C++11 will be any different; I might not know it well, but I do note that it has many of the same people behind it.
- throwawayaway 12y agoobviously we disagree! i think it's ok to miss out on language features. templates, as you say yourself you're ok not to know. you're also not ok not to know exceptions. there's other stuff too, you can get away without the C preprocessor. C++ is too big to know all of and it's a waste of time to invest time trying to, unless you are on a standards committee or are writing a compiler...(and even then you can get away with being a specialist!). it's much better to be a program writer than a language lawyer and dare I say it: more satisfying too. i draw a huge distinction between people that understand a language and people that can use a language, and i think people underestimate the time and effort in understanding a language. i think that time and effort could be better spent writing programs.
- egwor 12y ago
- pmelendez 12y agoAs other said, Meyer's book is highly recommended. Also, this talk would give you a very general overview of the new features of the language: http://channel9.msdn.com/Events/GoingNative/2013/Opening-Keynote-Bjarne-Stroustrup http://channel9.msdn.com/Events/GoingNative/2013/Opening-Key... Another book that can be a refresh introduction would be: http://www.amazon.com/Tour-C--Depth/dp/0321958314/ref=sr_1_1?ie=UTF8&qid=1419355516&sr=8-1&keywords=tour+of+c%2B%2B http://www.amazon.com/Tour-C--Depth/dp/0321958314/ref=sr_1_1...
- danieljh 12y agoIf you want to learn by examples, check out the following repositories: https://github.com/daniel-j-h/cpp14-snippets https://github.com/daniel-j-h/cpp14-snippets https://github.com/daniel-j-h/cpp11-snippets https://github.com/daniel-j-h/cpp11-snippets (Disclaimer: the C++14 version is still missing proper references to the official C++14 standard)
- w8rbt 12y agoYou may like to read and search the questions on stackoverflow. They have a lot of C++11 and C++14 questions and code examples and many of the contributors are very experienced with C++. http://stackoverflow.com/tags/c%2b%2b11/info http://stackoverflow.com/tags/c%2b%2b14/info I use C++ almost daily. I love it. I've used it for many years now. Having said that, I try to avoid the newer standards unless I absolutely must use them. Don't get me wrong. The new features are great. I love nullptr, fixed width integers, to_string, stol, etc. but I sometimes work in environments with very old compilers that don't offer these features. And when the only code you have is written for C++11 or newer, it can take a great deal of time and effort to make your code work on the older systems. Also, if what you need is in the standard, then don't use any external libraries. There are a lot of great libraries out there (Boost, Crypto++, etc.), but they add complexity and build dependencies and can cause all sorts of support issues. If you add Boost only because you need to parse arguments, then you're really causing yourself and developers who come after you more trouble than it's worth. So every time you think you need an external library, think twice and talk it over with other, more experienced developers. When I need more features than the older standard provides, I'll use a newer standard, but I strive to only use the exact features I need (don't go wild and convert your entire code to C++11). And as a very last resort, I'll use an external library (but only a mature, widely used one) when I cannot easily write what I need with std C++. Hope this helps. And whatever you decide, I'm sure you'll enjoy working with C++.
- cgh 12y agoI too worked with C++ for years but I haven't for some time. I plan to learn the C++11 stuff and get back up to speed because I hate the feeling of falling behind in a language that really has no competition in the niche it fills. Here is a somewhat off-topic question for you: what is the job market like for C++? Is it mostly maintaining/enhancing legacy code or is there considerable new code being written in C++?
- w8rbt 12y agoIt's been just more than two years since I was paid to write software. I was a systems programmer. My knowledge is a bit dated. The C++ code I write today is to support IT security research (job) and my own personal interests (hobbies). When I worked in systems programming (automobile systems research), C++ was very popular in the embedded/systems space. I believe it still is. Many systems people I knew were porting C to C++. Old code was maintained and new code was written. I'd say the break-down was about 50 50. In addition to adding C++ features, maintaining C compatibility was paramount. I never worked with higher-level applications, but I'm sure that there's a lot of C++ up there too (web browsers, office suites, etc). Maybe even more.
- pmorici 12y agoAlmost all of those new features are part of the C++11 standard so just get a reference that specifically says it has been updated for C++11. There is a list of C++ books on stack overflow.
- pagade 12y agoI have read and I would highly recommend C++ Primer 5th edition. Although my purpose was also to brush up old(?) features of C++. It covers everything except multi-threading. If you just want to skim - A Tour of C++ should suffice.
- qwerta 12y agoStart with QT libs. I hate C++ with passion for almost two decades. But I recently started working on KDE sub-project and found it very nice.
- discardorama 12y agoA (maybe unrelated) question about companies like Google and Faceook, which are C++ powerhouses: how many (if any) of the C++11 or C++14 features have they approved for use in production code?
- desdiv 12y agoFor Google open source projects, all C++11 features are approved except the following ones[0]: Functions (other than lambda functions) with trailing return types, e.g. writing auto foo() -> int; instead of int foo();, because of a desire to preserve stylistic consistency with the many existing function declarations. Compile-time rational numbers (<ratio>), because of concerns that it's tied to a more template-heavy interface style. The <cfenv> and <fenv.h> headers, because many compilers do not support those features reliably. Default lambda captures. For Chromium, it's a completely different set of rules[1]. [0] http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#C++11 http://google-styleguide.googlecode.com/svn/trunk/cppguide.h... [1] https://chromium-cpp.appspot.com/ https://chromium-cpp.appspot.com/
- discardorama 12y agoOSS projects would, presumably, have far fewer restrictions than internal revenue-bearing production use?
- ramgorur 12y agosame with me, I am a very old c++ coder, learned during 2001-2002. Now I am doing TA at a graduate school, instructing a course on c++. It helped me to learn a lot of new stuffs on c++11. "C++ Primer", by Lippman is the book that we try to follow.
- mb_72 12y agoIf 2001-2002 is old, then what is 'used for 7 years starting 1994'?! :) I will be curious to read the replies here, as a year ago I was considering different languages and environments for a cross-platform project, and ultimately C# (yes, C#) won out over C++. To be fair the requirements for the project meant that runtime performance wasn't so critical, but preventing the developer - myself! - from making mistakes was. Maybe it is because of my age, but despite having lots of experience with C++ and a mostly pleasurable love-sometimes hate attitude towards it, I couldn't imagine it making first choice for me these days for new projects.
- acqq 12y agoGo to the Stroustrup's site, the page with the contents of his "C++ 4th ed" book contains even the full drafts of the "Tour of C++" part of the book. http://www.stroustrup.com/4thContents.html http://www.stroustrup.com/4thContents.html
- diarg 12y agoYou want even MORE features in C++?. You have made Stroustrup happy.
- thdn 12y agoTake a look at Stephan T. Lavavej aka STL series at C9, http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL- http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavave... Totally worthy.
- lyhkop 12y agoaaa