13 ms·
A Tour of C++ (Third edition)
- pjmlp 4y agoQuite good reading to stay up to date how to write proper C++ code instead of classical C with C++ compiler, given how the language is anyway unavoidable in many domains until they migrate to something else, mostly beyond our lifetimes. Like LLVM and GCC contributions, GPGPU frameworks and Khronos standards, language runtimes,...
- throwaway81523 4y ago> Quite good reading to stay up to date how to write proper C++ code instead of classical C with C++ compiler, This is good too: https://github.com/isocpp/CppCoreGuidelines https://github.com/isocpp/CppCoreGuidelines I also liked Scott Meyer's book "Effective Modern C++".
- pjmlp 4y agoYes, although Scott Meyer's is now retired and his book series have stopped in C++14. Some other books on this front, "Beautiful C++: 30 Core Guidelines for Writing Clean, Safe, and Fast Code" https://www.amazon.com/-/en/dp/0137647840 https://www.amazon.com/-/en/dp/0137647840 "Embracing Modern C++ Safely" https://www.amazon.com/dp/0137380356 https://www.amazon.com/dp/0137380356 Also with clion and Visual Studio, it is possible to write code while having the static analysers ping back into the core guidelines.
- throwaway311022 4y agoDefine “proper”. For me, “proper” is readable code without too much magic and over-reliance to compiler to do optimizations. C-- and Orthodox C++ are there for a reason. People in the committee and Bjarne himself don’t write any production code, so anything they say, do, and standardize is taken with a ton of salt, often with sarcastic comments. It’s been years since anyone I know actually welcomed a new feature in the language. I don’t even understand where outlandish features like ranges are coming from. These don’t solve ANY of the real-world problems, so why even invent this when you can fix outstanding issues instead?
- snovv_crash 4y agoI feel like the standards are starting to get ahead of implementation. It's almost 2023 and C++20 still doesn't have even full support in any of the main compilers.
- pjmlp 4y agoVC++ is mostly crossing the finish line already. GCC is getting there thanks Red-Hat support. Clang well, apparently all those compiler vendors that profit from it, see only a value in LLVM itself, after Apple and Google switched focus to their own languages.
- cyber_kinetist 4y agoThere's a looming feeling that C++17 is really going to be the last version of C++ (practically, in production). The Vasa is now half-sunk [0][1], but the alternatives are yet to be truly born. The current issues surrounding the language standards: - The important but half-baked features of C++20 that has never really been polished enough for actual production usage (modules, coroutines) - Unnecessary "hyper-modern" C++ features which are dead on arrival (ranges) - The dramatic increase in build times due to the STL library (which are accelerated by those hyper-modern C++ features) [2] - The fleeing of LLVM/Clang engineers to other projects (as you've said, Apple engineers shifting work to Swift, and Google abandoning Clang and moving to Carbon). - Implosions in the ISO committee (notably the controversy surrounding the rape convict) It's really not looking good, but there aren't that much alternatives so I think people will just stick to C++17 for the moment. Listing the worthwhile competitors: - Rust is a bit too awkward to use in many cases where C++ is used (particularly with unsafe Rust), and inherits some of the hyper-modern complexities/insanities of C++. - Zig is still too unstable, they just finished reworking the compiler - Jai is not even released to the public - D might be a candidate but IMO they should really commit 100% fully for GC-less betterC mode... - Nim still has many warts and unbaked features, and also there was a split in the compiler team [3] [0] https://www.aristeia.com/TalkNotes/C++vstheVasa2-ups.pdf https://www.aristeia.com/TalkNotes/C++vstheVasa2-ups.pdf [1] https://www.stroustrup.com/P0977-remember-the-vasa.pdf https://www.stroustrup.com/P0977-remember-the-vasa.pdf [2] https://old.reddit.com/r/cpp/comments/o94gvz/what_happened_with_compilation_times_in_c20/ https://old.reddit.com/r/cpp/comments/o94gvz/what_happened_w... [3] https://github.com/nim-works/nimskull https://github.com/nim-works/nimskull
- Triangle9349 4y agoRelated link: The Definitive C++ Book Guide https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list https://stackoverflow.com/questions/388242/the-definitive-c-...
- sizzzzlerz 4y agoHaving left the C/C++ professional programming world several years back to wallow in other pastures, I've lost close touch with the languages except at a low-key hobbyist level. That said, I am curious over what is the motivation to pursue updates in 20 and 23? Are there really new features promised that today's programmer simply can't live without or are they all various levels of syntactic sugar or something in between? Is there a concern over whether these changes are making the language ever more complex and obese thus making mastery even harder to achieve?
- Deukhoofd 4y agoOne of the things I've mostly been looking at is the additions to the standard library. Especially the new <stacktrace> header looks like something that should have been in the language already.
- helen___keller 4y agoI can’t speak for all of C++20/23 but I was impressed by Concepts which finally make template compile errors legible
- DoingIsLearning 4y ago> Having left the C/C++ professional programming world several years back to wallow in other pastures. As someone who wants to follow the same trajectory, how did you do it? And how did you dissociate professionally from being seen as the C++/systems guy?
- _dhruva 4y agoHaving gone through a very similar journey, it took around 2 years for me to completely disassociate myself from a specific programming language. It was more a 'me' problem since I leaned on to a programming language rather than a problem domain. I still consider myself a systems programmer mostly writing glue code in Go/Python and jumping into C/C++ as required to improve performance when required.
- sizzzzlerz 4y ago
- npalli 4y agoTo focus on the book itself, the very first "hello world" example doesn't seem to work with any compiler. Literally import std; int main() { std::cout << "Hello, World!\n"; } I even tried futzing with the latest compilers - VS 2022 Preview and clang++ 16.0.0 and it wouldn't work. Perhaps it works in some specific earlier released versions? As somebody noted, perhaps this book is for reading and not for actually trying out the code. Very strange for a programming language book in 2022.
- Sin2x 4y agoYou need to include iostream https://en.wikipedia.org/wiki/Input/output_(C%2B%2B)#Input/output_streams https://en.wikipedia.org/wiki/Input/output_(C%2B%2B)#Input/o...
- npalli 4y agoNo, this is about modules. See first line and this is verbatim from the book.
- Sin2x 4y agoYou're right. Apparently, it's supported only by MSVC at the moment (Standard Library Modules): https://en.cppreference.com/w/cpp/compiler_support https://en.cppreference.com/w/cpp/compiler_support https://github.com/microsoft/STL/pull/3108 https://github.com/microsoft/STL/pull/3108
- jeroenhd 4y agoOther compilers support modules in varying ways as well, but there's no universal module "std" yet. Clang also requires some more command line flags to build modules it seems and g++ needs a command line flag to enable module support as well. Microsoft's compiler seems to have the best language support in many areas, but seems to fail in others (notably the "core language features"). Then again, the standard isn't finished yet. If I were to write a program in modern C++ I'd go for the Microsoft compiler. The open source and free implementations are clearly not capable of keeping up with a commercial software powerhouse when it comes to a complicated language like C++.
- didgetmaster 4y agoThis is an obvious ad to sell a book, but I wish more publishers would let you read one of the chapters without buying it first. Stroustrup has a lot of books and I have read some of them so he is a known entity, but I see ads like this all the time from authors I know nothing about. The preface and table of contents are good information, but they don't give you a good sense of the author's writing style.
- frou_dh 4y agoIf you click through to the InformIT site then you can get a PDF of Chapter 12 (Containers).
- photochemsyn 4y agoLooking around the site, there's a free pdf chapter available via the publisher link (Chapter 12, Containers). https://ptgmedia.pearsoncmg.com/images/9780136816485/samplepages/9780136816485_Sample.pdf https://ptgmedia.pearsoncmg.com/images/9780136816485/samplep... It's worth comparing that to one of the more popular free C++ resources, learncpp: https://www.learncpp.com/cpp-tutorial/container-classes/ https://www.learncpp.com/cpp-tutorial/container-classes/ The 'advice' section in the Tour excerpt is perhaps the most useful part. The learncpp excerpt is more about writing your own container class - note that many would consider the examples outdated with lots of raw new and deletes, but others would say, how else would you learn why uniq_ptr was introduced? (learncpp covers that later). As far as how containers are allocated, C has malloc, calloc and free; new and delete in 'C with classes C++' are wrappers around those functions, and modern C++ has unique and shared pointers as wrappers around new and delete in turn. Actually learning modern C++ in depth thus seems to require going through that whole chain, including gaining a solid understanding of stack vs. heap, and the benefit is improved performance relative to languages like Python and JavaScript. There's a notion that one can prototype in Python and then just translate that easily to modern C++, using idioms like ranges, without necessarily knowing the history of C++. It's an interesting idea, seems to be fairly popular, but I'd guess you'd still need to have that foundation in C to make it really work well.
- CamperBob2 4y agoThere's a notion that one can prototype in Python and then just translate that easily to modern C++ That was my first thought on looking at the github link posted by waynecochran above: if I'm going to write C++ code that looks like that, why don't I just use Python or a similar language? What exactly is C++ doing for Wayne here? It's not going to be much slower if it all, given that all he's doing is invoking higher-level abstractions. Another thought: again, given the abstractions and high-level resources that C++ programmers will be coming to rely on in the years ahead, someone could "just" write a back end that translates a cleaner high-level language like Python to modern C++ for compilation and optimization.
- pjmlp 4y ago
- waynecochran 4y agoI’ve been writing C++ code since it’s inception in the 1980’s. In the last two weeks I’ve written close to 1000 lines and no raw ptrs… in fact no smart ptrs either… not even one c-style array. No worries about leaks or memory safety. It doesn’t look anything like C++ code I wrote even 10 years ago.
- Icathian 4y agoI'm curious and would love to take a look. Any chance any of that code is available somewhere? My c++, little that I write, mostly looks like C and I'd love to learn something new.
- waynecochran 4y agoMost of its in a private GitHub repo but I think I can open a piece of it… here is part of it ... a header only library for computing closest pairs... https://github.com/wcochran/closest-pairs/blob/main/closest-pairs.h https://github.com/wcochran/closest-pairs/blob/main/closest-...
- mike_hock 4y agoWhy is Eigen/Dense included if you never refer to anything Eigen and just take it as a duck-typed template parameter?
- waynecochran 4y agoTrue.. good eye .. the operations on type P are very Eigen specific, but another type could easily provide those.
- bugfix-66 4y agoAfter giving your code a quick skim, I cannot see any mistakes in your vector indexing. However, your code is full of vector accesses without bounds checking: vec[i] instead of vec.at(i). That's just as "unsafe" as C, so I recommend not bragging about how far you've come. Your code is full of what is essentially unprotected C-style *(addr + i) = ... ... = *(addr + i) You've been writing C++ since the 1980's, but your code is full of raw pointer math, and yet... "No worries about memory safety"? I have a feeling you'll be reaching for Valgrind or address sanitizer someday soon, just like the C programmers.
- deleted 4y ago[deleted]
- mk89 4y agoI don't have the professional experience that most of the commenters here have, but I hear a lot of negativity. Like, a lot. Sure, the compilers might be a little bit behind, but who cares, I believe it's just a matter of time before they implement the missing features. They are pretty solid, the libs are battle tested, the ecosystem is huge (which can be an issue too). For me the bigges issues are: - lots of pre-11 docs and blogs showing up in the first 1-2 search pages - not clear answers or FAQs about how to develop cross platform code (and backward compatible), the devil is always in the details here. - not always clear which tool to use: what do I use for unit tests? And coverage? I would like to have like 2-3 top used libs, the rest I don't care - some things which should be basic in 2022 can be daunting for people coming from simpler languages like Python or Javs, stupid example: dates. I see that with c++20 they did a lot of good work (with chrono, not sure if there is anything else), but that's not enough. The API is really good, but it's quite minimalistic for a 2020 standard. You can clearly live with that, but if you want to keep the language competitive you need to provide also higher level constructs. (Just to say some BS: Take Python's date module and copy it as is.) Finally, if you exclude all the features you won't probably ever use, focus on simplicity and use the tools at your disposal (clang-tidy, clang-format, etc.) I think things are quite OK. But hey, I am not paid to work on old c++ codebases so of course I might be biased :)
- qualudeheart 4y agoIs anyone reading the C++ standard or is it just me? It acts as an excellent reference manual.