9 ms·
I'm glad this hasn't turned into (so far) the usual "c++ is dumb" flame fest. I've really enjoyed programming in c++17 for the last three years (I had the luxu
by gumby 7y ago
I'm glad this hasn't turned into (so far) the usual "c++ is dumb" flame fest.
I've really enjoyed programming in c++17 for the last three years (I had the luxury of starting from an empty buffer) and find the language pretty expressive. If you are able to use it as a "new" language, ignoring its C roots and features that exist pretty much just for back compatibility, it's really quite expressive, powerful, and orthogonal.
I'm actually pretty glad the c++ committee has been willing to acknowledge and deprecate mistakes (e.g. auto_ptr), to squeeze out special cases (e.g. comma in subscripting) and to attempt to maintain generality. Conservatism on things like the graphics standard is reducing the chance of the auto_ptr or std::map mistakes.
- fnord77 7y agolast time I used C++ was in the mid-2000s. With all the new features since then, I assume the "proper" way/style to right C++ has changed since then?
- gumby 7y agoI don't know if you mean formatting, in which case I don't believe anything has changed (pretty much anything goes) but yes, you can now do for (auto [x, y] : list_of_coordinates()) ... and things like that.
- gameswithgo 7y ago* is now deprecated.
- gumby 7y agoNot formally, but as you were responding to a comment on style: indeed, you don't really need * that often; there are more powerful, safer options in most cases. But C++ is a systems programming language and * is still quite useful.
- CodeMage 7y agoThis is not even remotely true. Let's say you have: std::unique_ptr<foo> m_foo; How do you pass that into a function that can receive a pointer to foo, but does not require it? The only way to do so is to declare the function to take a foo* and pass it m_foo.get() In summary, * will never be deprecated until C++ has support for something along the lines of Rust's borrowing and lifetimes.
- Leherenn 7y agoI am not sure I understand what you mean, but now (c++17) you can use an optional in this case.
- paulddraper 7y ago> How do you pass that into a function that can receive a pointer to foo, but does not require it? Same as you would have a function that can receive an `int` but does not require it. Or a receive a `std::vector` but does not require it. I surmise that you mean "how do you pass any value (pointer or otherwise) into a function that can receive a value but does require it". And I surmise you have before used pointer indirection to pass that value because it has a conventional sentinel value of 0/NULL/nullptr. You are correct in that optional values did not have a standardized solution, until C++17 std::optional. If you don't have C++17, I recommend one of the equivalent third-party implementations: * https://www.boost.org/doc/libs/1_52_0/libs/optional/doc/html/index.html https://www.boost.org/doc/libs/1_52_0/libs/optional/doc/html... * https://github.com/akrzemi1/Optional https://github.com/akrzemi1/Optional
- deleted 7y ago[deleted]
- jcelerier 7y agostd::optional does not support references (std::optional<MyVeryLargeType&>) however unlike boost, so this precludes usage with non-copyable types.
- paulddraper 7y ago
- MauranKilom 7y agoLargest changes (most from C++11, some from C++14 and C++17) are: - std::unique_ptr and std::shared_ptr (your code should not have any new/delete). It's easy to write code with clearly defined ownership semantics, and I've yet to create a memory leak. - Proper memory model so that multithreading has defined semantics. - Lots of syntactic sugar (auto, range-for, lambdas, structured bindings, if constexpr, etc.). - More metaprogramming tools/fun. C++11 alone is a very different world compared to what you are probably used to.
- noobermin 7y agoGenerally good things, but I get triggered when I hear people call metaprogramming "fun." Such is the beginning of all sorts of woes.
- ncmncm 7y agoMany of the improvements are to make metaprogramming increasingly unnecessary. I practically don't use it at all anymore. But coding on C++ has become quite fun. Generic lambdas deserve much of the credit.
- sramsay 7y ago> - std::unique_ptr and std::shared_ptr (your code should not have any new/delete). It's easy to write code with clearly defined ownership semantics, and I've yet to create a memory leak. I cannot begin to describe how huge a thing this was for me. I came to C++-17 (just about) from C++-98 -- a language I hated so much, I vowed I would never, ever write anything in it on purpose. It is a massively different beast today from what it was, but the biggest thing of all is this change in how you deal with memory. It was like going from a particularly annoying and verbose aberation of C to a particularly fast and expressive version of Python. YMMV, of course. In fact, it may vary to the point of becoming absolutely unrecognizable if you're dealing with a massive legacy codebase. But I have to say, I've become a very big fan in the last few years.
- axilmar 7y ago
- beetwenty 7y agoThe thing that has really kept me from getting behind updates to the C++ universe is the lack of progress on improving the state of build tooling. It is miserably underengineered for modern, dependency-heavy environments. C++20 does introduce modules, which is a good push towards correcting the problem, but I'm still going to be "wait and see" on whether the actual implementation pans out.
- Fronzie 7y agoAlthough I agree with your point, cmake+vcpkg goes a long way for hobby projects, cmake with a bit of custom scripting goes a long way for larger scale projects. The cmake language might not be beautiful, but it does allow for simple sub-projects/library scripts once the main cmake script is set up properly.
- gumby 7y agoWell, there's Conan, which helps a bit, but these days what I simply do is use CMake to download a package from GitHub or wherever and build it. Sadly the C++ ABIs are standardized the way that C ABIs are (I'm OK with why but it's unfortunate in that it creates a barrier) so you have to have separate libraries compiled with g++ and clang++ if you use both on your platform (we use both because they catch different bugs, and for that matter exhibit different bugs). But it means you can't simply install, say, fmt in any system-wide directory like /usr/lib or /usr/local/lib Just as an amusing side note: Common Lisp used to be criticized for the massive size of its libraries and later likewise C++. It was true they were quite large. Now both are criticized for their tiny libraries. Which by today's standards they are.
- dvdhnt 7y agoI have seen comments that suggest you can write cross-platform applications (or at least shared business logic) in c++. Is that the case? If so, how would you recommend someone go about learning c++?
- gumby 7y agoI read Stroustrup's "tour of C++" then looked specifically for blogs that talked about C++ 17. And wrote a lot of code with all warnings enabled. Yes you can write cross platform applications though perhaps only the engine, not UI.
- McP 7y agoQt is great for cross platform UI, for Mac/Win/Linux at least
- 77pt77 7y agoLast time I checked QT depended on a signal/slot mechanism that was not C++ compatible. There was a code generator. Has this changed?
- xfer 7y agoNo. But there are alternatives to moc like: https://github.com/woboq/verdigris https://github.com/woboq/verdigris .
- 77pt77 7y agoThank you. Very interesting work.
- de_watcher 7y agoIf you use CMake you don't see that generator. It automagically works.
- jcelerier 7y ago
- tsimionescu 7y ago> it's really quite expressive, powerful, and orthogonal Expressive and powerful are definitely true, but I'm not so sure about 'orthogonal'. Most C++ features seem to depend heavily on each other, and library decisions can impose restrictions/boilerplate on application code in many areas. Especially as the language has evolved, features like exceptions, destructors, copy and move constructors, and operator overloading have become more and more indispensable. Template functions are still required for any kind of variance (e.g. you still can't have a non-template function that works on a const std::shared_ptr<const *base_type> or any derived type). None of these is unbearable, but I do believe that even the modern subset of C++ is still the least orthogonal mainstream language in use (and definitely the most complicated by far). To be fair, it's also likely the most expressive mainstream language too, and still the most performant.
- mike_hock 7y ago> you still can't have a non-template function that works on a const std::shared_ptr<const *base_type> or any derived type I guess you meant, you can't have a function that accepts a shared_ptr to the base type without indirectly using template machinery? Because you can most definitely have a function that does this that is not a function template. #include <memory> #include <iostream> struct foo { virtual ~foo() = default; virtual void bark() const { std::cout << "fork\n"; } }; struct bar : foo { void bark() const override { std::cout << "bark\n"; } }; void poke_so_it_barks(std::shared_ptr<foo const> const thing) { thing->bark(); } int main() { poke_so_it_barks(std::make_shared<foo>()); poke_so_it_barks(std::make_shared<bar>()); }
- tsimionescu 7y agoOops, I picked a bad example it seems... Apparently `shared_ptr` does some magic to simulate covariance through type conversion. It still breaks in other cases (a function which returns a `shared_ptr<derived>` can't override a function which returns a `shared_ptr<base>`, unlike with derived* and base* ), but it still probably covers most real-world cases. If I had stuck with std::vector my point would have been better. Even though theoretically a `const std::vector<derived* >` IS-A `const std::vector<base* >`, that is, a read-only view of a collection of derived elements behaves the same as a read-only view of a collection of base elements, you can't pass the first to a function expecting the second in C++, unless you make your own function a template.
- dotancohen 7y ago> I had the luxury of starting from an empty buffer Let's assume that I'm willing to flush the cache. Are there and C++17 learning resources that you might recommend? My day-to-day languages are Python and scripting languages.
- gumby 7y agoFor me, pls see my comment https://news.ycombinator.com/item?id=21456353 https://news.ycombinator.com/item?id=21456353 Also the books by the person whose blog spawned this comment thread seem to be pretty good.
- zelly 7y agoCppreference (learn by doing and look stuff up as you go) https://cppreference.com https://cppreference.com The ISO C++ Standard draft (unironically—it's actually quite readable and is actually up-to-date unlike a lot of books) https://wg21.link/std https://wg21.link/std Tour of C++ (book) by Bjarne Stroustrup (start here, you can read it in one weekend)
- missblit 7y agoNot sure I'd recommend the C++ standard for learning the language for a couple of reasons: * It's gosh darn huge * While not the hardest standard to read, it is still a standard, so has to be focused on really really low level detains and precise complete explanations instead of being a good learning resource That said it is a great resource if you're ever confused about some corner of the language -- a lot of articles explain things slightly incorrectly.
- seisvelas 7y agoWhat does orthogonal mean as an adjective for a programming language? I've never heard that word outside of math and I always get excited by a word that might expand my ability to think about code.
- sorokod 7y agoNot the OP but guessing that in this context probably means independent of historical baggage.
- tomlu 7y agoEvery feature controls one "dimension" of a language, and can be freely combined with other features that control other "dimensions" without worrying about how they interact. I am quoting the word "dimension", because applying a precisely defined mathematics concept to something messier (like programming) will require a certain amount of hand waving and squinting.
- lone_haxx0r 7y agoImagine a programming language that gives you three different ways to add 2 numbers: 1 + 2; std::add(1, 2); std::int(1).add(std::int(2)); That's is not orthogonal at all, since we have 3 different ways to do the same thing for no discernible reason. An orthogonal interface is one where there are fewer reasonable ways to do something, and each function/operation has it's role clearly defined, it doesn't try to do things unrelated to its main role, and the interface doesn't mix different layers of abstraction (like intertwining OOP and arithmetic in my 3rd example, when there already are native arithmetic operations).
- gugagore 7y agoOne place where this shows in a fairly technical way is in discussing instruction sets: https://en.wikipedia.org/wiki/Orthogonal_instruction_set https://en.wikipedia.org/wiki/Orthogonal_instruction_set "In computer engineering, an orthogonal instruction set is an instruction set architecture where all instruction types can use all addressing modes. It is "orthogonal" in the sense that the instruction type and the addressing mode vary independently. An orthogonal instruction set does not impose a limitation that requires a certain instruction to use a specific register[1] so there is little overlapping of instruction functionality.[2]" Its use here is more general, but I hope the specific example helps.