Language

CppCon 2017: Nicolai Josuttis “The Nightmare of Move Semantics for Trivial Classes”



CppCon

http://CppCon.org

Presentation Slides, PDFs, Source Code and other presenter materials are available at: https://github.com/CppCon/CppCon2017

Assume, we implement a very simple class having just multiple string members. Even ordinary application programmer prefer to make it simple and fast.

You think you know how to do it? Well beware! It can become a lot harder than you initially might assume.

So, let’s look at a trivial class with multiple string members and use live coding to see the effect using different implementation approaches (using constructors passing by value, by reference, by perfect forwarding, or doing more sophisticated tricks).

Sooner than later we will fall into the deep darkness of universal/forwarding references, enable_if, type traits, and concepts.

Nicolai Josuttis: IT Communication

Nicolai Josuttis (http://www.josuttis.com) is an independent system architect, technical manager, author, and consultant. He designs mid-sized and large software systems for the telecommunications, traffic, finance, and manufacturing industries.

He is well known in the programming community because he not only speaks and writes with authority (being the (co-)author of the world-wide best sellers The C++ Standard Library (www.cppstdlib.com), C++ Templates, and SOA in Practice), but is also an innovative presenter, having talked at various conferences and events.

Videos Filmed & Edited by Bash Films: http://www.BashFilms.com .(tagsToTranslate)Nicolai Josuttis(t)CppCon 2017(t)Computer Science (Field)(t)+ C (Programming Language)(t)Bash Films(t)conference video recording services(t)conference recording services(t)nationwide conference recording services(t)conference videography services(t)conference video recording(t)conference filming services(t)conference services(t)conference recording(t)conference live streaming(t)event videographers(t)capture presentation slides(t)record presentation slides(t)event video recording

Source

Similar Posts

27 thoughts on “CppCon 2017: Nicolai Josuttis “The Nightmare of Move Semantics for Trivial Classes”
  1. 38:30 The problem here is that you're using C++ :q
    I mean, are you fucking kidding me?! All this intricate edifice of high-falutin' templating code just to do the string initialization right? Well, then I'd rather do it in plain old assembly in no time while you will be wondering how to slay another Hydra you created and what language rule from the 1337th page of the Standard does it break.
    Yes, I'm dead serious right now: writing code in assembly has officially become easier than doing it in C++.

  2. That's a very good presentation after all. It summarizes many things regarding pass-by-value and pass-by-reference techniques, and clearly describes the mentioned problems. I like it.

  3. Mind blowing ….. wow….. mindddaaaaaa blooooowwwwwinnnnngggggggg……
    This is exactly what I was looking out for. I am so much thankful to you Nicolai. WOW!

  4. This is depressing. All I could say is, make it a standard to guarantee that the compiler will construct it in place if it an object is constructed out of a temporary.

  5. On my machine, using MSVS 19.1030324, adding the line "using customer::customer" makes "VIP v{"Boss"};" fail to compile, citing ambiguous constructor.

  6. 14:46 but aren't the "Joe" and "Fix" literals copied in to the constructor arguments f and l before they are moved?
    So 2 mallocs when they are created and then 2 when they are copied and then 2 moves ?

  7. Here's an example of aggregate initialization: http://cpp.sh/3uq4h
    I personally feel like this is the best route though I guess it depends on the members you're using.

    EDIT: Also note that you can actually remove that constructor deletion line and it will still work uninitialized! You can also do crazy stuff like this with the copy and move constructors: http://cpp.sh/6auh2

    That does actually move the strings internally if possible though that won't work if not every member is movable.

  8. Move semantics are bad in so many ways. Yes, they can provide some 'magical' performance gains where the programmer is lazy and just treats everything like values, but the cost is high complexity code with unclear semantics. Digging the guts out of an object during a move and then leaving that object in an undefined state can introduce new STATE into a program that is hard to reason about. This CppCon talk should be proof enough that c++ needs a rethink/cleanup.

  9. I had this on as white noise while at work. Wasn't really paying attention. Then I looked over when the video hit 12:30, and I nearly threw up at my desk. That is disgusting…

  10. Please if you comment that c++ is ridiculous ,hard or what ever then you've not come to think of type of programmer you are and what you are really doing in programming field. And remember this tutorial is not for beginners.

  11. a) why do you have to support any possible string representation in the first place?
    b) why not use method overloading for the 1 argument case? instead of sfinae + default args
    c) if you have to support all cases why not use a builder pattern.

    i don't see the point. the stuff i have to do in java is much worse

  12. Don't make C++ 20 full stop and get rid of C++17, you are fucking up the language, it is MEANT to be complicated! You are changing too much shit.

  13. When he said that the arrayness of the arguments didn't decay I went "Oh _god_."

    Because that means every length of string literal bloats the binary for no good reason. If there is any nontrivial action in your perfect forwarding constructor…

  14. Microsoft is correct here. It should be const char *& not const char *, because you make a non-universal reference i.e. a rvalue reference to a const char *&& (non-forwarding)

  15. Umm.. either use C++ 17 string_view or std::move in the construction initialisation. Not even sure why the last horrible template solution got discussed. I think Nicolai missed having coffee.

  16. This should be basic for c++ programmers. The lesson is "don't make poor choices about what value category and how qualified my function's arguments are". There are way more wrong ways to do something than right ways. Other programming languages say "malloc, shmalloc". It's not hard to be better than that.

Comments are closed.

WP2Social Auto Publish Powered By : XYZScripts.com