CppCon 2015: Herb Sutter "Writing Good C++14… By Default"

39 thoughts on “CppCon 2015: Herb Sutter "Writing Good C++14… By Default"

  1. does someone know how to reproduce the errors for example 1 using code analysis @46:30 , what rule to set ?

  2. reinterpret_cast is OK if you're interfacing with a C-style library (like OpenGL for example)? I use them there.

  3. hey we are better than Rust by being more specific unsafes… dude… if it weren't for your insane momentum you should be calling them Daddy.

  4. in C, I had to remember and keep track of my memory usage. Some people complained that was too difficult. They made a change to modern C++. Now I need to remember…. that.

  5. Rust requires extensive annotations? 「(゜。゜)」??
    It may have been true before 1.0, but it's definitely not true now…
    The whole language is much less confusing that "Modern C++". It also has less overhead for a lot of the stuff (C++ variants suck really bad, for example…), and already solved the concurrency problem as well. Instead of dissing other languages perhaps Herb should try to learn from them…

  6. I wonder if these static analysis tools work when the memory validations happen separated in the code. For example if a function created a pointer to that vector… Oh forget it, since I started writing this he started to cover this point. 😀

  7. why isn't thing.bytes() thing.byteCount() or thing.numberOfBytes()? If you say in the explanation "number of bytes" but it still says bytes() which I would have presumed returned a byte array then you've done something wrong.

  8. I don't really know C++. How can I learn how to do it how he mentions it @ 2:00 without having to go through the code on the left hand side.? In other words, learn C++14 from C [or scratch], not from C++03. I come from a C background as implied. I'd like to develop good habits from day one!

  9. Herb explains things so much better than Bjarne. Everything is nice and clear, even for a beginner like me. Thanks Herb! 🙂

  10. Anyone else feel like they are trying to make a "C++ for dummies" language out of it? I mean, if you are writing in C++ you should have a full understanding of your pointer arithmetic and memory allocation/deletion. C++ doesn't need to be more simple, its already a great OOP language to use and very fast 🙂

  11. I tried to use smart pointers in a smaller new project. I'm sorry but i can't get myself behind it. It uglifies the code where readability is the most important part. Lambdas and r"sql( )sql" strings are the best. I only want a better stdlib and multiple return values from functions.

    Unfortunately modern C++ is also using much more memory and performance. So i upgraded from C with classes to C with lambdas.

  12. +Vasiliy Galkin I think it's because gsp is a global variable so f() or any other fuction f() may call can access gsp directly and modify it (f.e. call gsp.reset()), so gsp' could be invalid.

    Using sp means you increase the ref count so even if f() or any function f() calls modifies gsp, the ref count won't go down to 0 and delete the pointer's object.

    It confused me too because Herb wasn't clear about the fact that gsp can be accessed and modified from the functions, even tho he said that (was thinking about what can change the pointer and not the owner).

  13. C++ is changing so much, and backward compatibility is becoming such a pain. Wouldn't it be better to just create a NEW language with just the good new stuff of C++, which doesn't have to maintain backward compatibility? Are there any initiatives like these?

  14. It kinda disturbs me that Herb pronounces things like "shared_ptr" as "shared putter" rather than "shared pointer"

  15. How does copying a shared_ptr protected from side effects from callees when both the orignal and copy shared ptr's point to the same underlying memory? [1:01:00]
    Dead confused….
    Any replies?

  16. No, you don't create a copy, you just create another object that points to the same thing (same memory address). A real copy would do the job.

  17. Exactly, both will be invalidated, because they both point to the same thing. Reference counter is not going to prevent that. I wonder how nobody complained about that. What you need in this case is another copy: auto sp = std::make_shared<int>( *gsp );

  18. [Completing previous comment] As Herb said : "You take a copy of a shared pointer before you turn it into a raw pointer and pass it on a call tree". His point is that the tools he is presenting helps you to remember to do that.

  19. I am not an expert (at all), but I think the second method works because you create a copy of the smart point global_sp into the local sp. This should increment the number of existing references (pointers) to *global_sp (that's what smart pointers are for). With such a copy, it is now impossible for f() to completely invalidate global_sp using only sp.get() because there will be at least 1 more reference to *global_sp due to the copy before the call. Youtube response comments are too short ><.

  20. I've written it wrong, f(global_sp) should be replaced by f(global_sp.get()), and f(sp) –> f(sp.get()).
    Yet, my question remains open.

  21. I didn't get the example about shared_ptr (slide precisely at 1:00:00).
    What Herb claims:

    void f(int* p) { /* might invalidate p */ };
    shared_ptr global_sp = …;
    int main() {
    f(global_sp); // bad, and tool confirms it
    auto sp = global_sp;
    f(sp); // OK, checker tool also has no complaints.
    return 0;
    }

    I can't get it why second case is a good scenario. When we assign global_sp to sp, they both still point to the same data. Given that, f(sp) will invalidate both.

  22. The examples around 1:20:55 don't compile because you can't bind a non-const int& to the return of std::min

  23. -1 because:
    Visual Studio is free tool if you are open source developer. Look at Community edition.
    Herb Sutter works for Microsoft so, yeah, he is firstly implementing everything for Visual Studio I guess and than it comes to clang or gcc.
    And at last but not least as Zarviroff Serge said – it doesn't matter – it's about C++ and you not IDE or operating system.

  24. Sounds exactly like the presentations of Rust, although here you opt-in to the security(you also need to know where to opt-in).
    Now both languages have learned(and stolen) a lot from each other 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *