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

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии •

  • @amaarquadri
    @amaarquadri 3 года назад +7

    You know that something is amazing when it seems so natural and obvious that in hindsight you wonder why something like it wasn't done a decade earlier!

  • @MrSparc
    @MrSparc 9 лет назад +2

    Thanks CppCon for share this videos early on! Look the number of views in few hours! Please continue posting other talks for all of us that unfortunately can't assist this great event with the C++ family. CppCon you're rock!!!

  • @MaherBaba
    @MaherBaba 9 лет назад +2

    I could watch these all day

  • @JCStelu
    @JCStelu 8 лет назад +7

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

    • @JCStelu
      @JCStelu 8 лет назад +1

      Benjamin Rood I couldn't say, since I am yet to listen to many of the C++ guys, but he sure is a great one! :-)

  • @Aleh_Loup
    @Aleh_Loup 9 лет назад +5

    Fantastic presentation!
    Amazing work, getting memory safety without too much annotation is fantastic.

  • @mathieusoum6994
    @mathieusoum6994 9 лет назад +4

    [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.

  • @MrAbrazildo
    @MrAbrazildo 6 месяцев назад

    2:00, I know this is just a silly example. But it's nice to point some things. I use to separate the midia (big data) of a circle, from "its logic", which is likely to fit on caches. So it becomes an "OO inspired by DOD" approach.
    As for for range loop, despite being a C++11 thing, I only passed to use it from C++14. It was required to specify the type. So on those years I used a macro of my own, which deduced the type, at the cost of using pointer syntax. I think "auto all the things" is gold.
    3:31, good, because there are old things with bad reputation, that actually are pretty useful - macro, old enum, someone could say unions. So, don't make mistakes Carbon folks are already doing!

  • @enhex
    @enhex 8 лет назад +3

    +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).

  • @jeffdovalovsky7259
    @jeffdovalovsky7259 5 лет назад +4

    Does a crossword-puzzle or scrabble board use a 2-dimensional string?

  • @kimicochiang
    @kimicochiang Год назад

    I love this video so much.Really appreciated.

  • @maxx666mayhem
    @maxx666mayhem 8 лет назад +1

    Awesome presentation, very educational.. Thanks for sharing...

  • @VileLasagna
    @VileLasagna 9 лет назад +54

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

    • @yemiez
      @yemiez 8 лет назад

      +Vile Lasagna Same x_x

    • @HobokerDev
      @HobokerDev 8 лет назад +2

      +Vile Lasagna I think he said "pointer" once.

    • @ruadeil_zabelin
      @ruadeil_zabelin 8 лет назад +5

      In another video he also talked about stuhduh instead of std

    • @isakbuhl-mortensen1967
      @isakbuhl-mortensen1967 8 лет назад

      He does that in this one too ^ ^

    • @SamVsCode
      @SamVsCode 8 лет назад +11

      He wanted to rhyme sutter with putter

  • @dasnacl
    @dasnacl 9 лет назад +1

    This is great! I can't wait for C++14! :D

  • @ChefSalad
    @ChefSalad 2 года назад +3

    The one thing about this newer style of C++ that I really hate is the keyword "auto". I always find it harder to figure out what's going on without the types being laid out explicitly.

    • @InXLsisDeo
      @InXLsisDeo 2 года назад

      If you use a modern IDE, it always tell you what's the type is just by having the mouse on the variable name.

  • @ecinZtark
    @ecinZtark 8 лет назад +3

    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!

  • @mathieusoum6994
    @mathieusoum6994 9 лет назад +1

    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. RUclips response comments are too short >

  • @robbie_
    @robbie_ 6 лет назад +3

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

    • @MagnificentImbecil
      @MagnificentImbecil 2 года назад +2

      reinterpret_cast is often wrongly used to convert "pointer to T" to "pointer to U"
      when T and U are "unrelated types" (e.g. char and unsigned char)
      and static_cast does not seem enough,
      but in fact static_cast really is enough:
      const U *pointer_to_const_U = static_cast (static_cast (pointer_to_const_T));
      I believe reinterpret_cast remains useful for converting pointers to integrals (e.g. of type std::uintptr_t or std::size_t) and... anything else, anyone ? (-:

  • @CdTCzech
    @CdTCzech 9 лет назад +3

    -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.

  • @BloodHaZaRd666
    @BloodHaZaRd666 6 лет назад +1

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

    • @SrIgort
      @SrIgort 3 года назад

      Good question, of someone discover please tell us

  • @jvsnyc
    @jvsnyc 3 года назад +1

    Lots of points for correctly using the term "dangling pointer". Too many otherwise good sources seem to confuse the meaning.

  • @VasiliyGalkin
    @VasiliyGalkin 9 лет назад +2

    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.

  • @Orgyilkos
    @Orgyilkos 7 лет назад +1

    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. :D

  • @EnthusiasticCoder
    @EnthusiasticCoder 9 лет назад

    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?

    • @EnthusiasticCoder
      @EnthusiasticCoder 8 лет назад +1

      +MaidePlays So its upping the count by 1 to keep things alive.
      Is this a threading issue?

    • @EnthusiasticCoder
      @EnthusiasticCoder 8 лет назад

      +MaidePlays I dont remember the code.

    • @EnthusiasticCoder
      @EnthusiasticCoder 8 лет назад

      ***** Ok i remember the code. So what's the fix that Herb suggests for this dangling pointer problem? Surely any new shared ptrs put in will also point to the same ptr?

    • @EnthusiasticCoder
      @EnthusiasticCoder 8 лет назад

      ***** A copy of the shared Ptr I remember.

    • @EnthusiasticCoder
      @EnthusiasticCoder 8 лет назад

      Ok - I tried your sample code and as you say it works. Thanks!

  • @treyquattro
    @treyquattro 7 лет назад +5

    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.

  • @RyanHaining
    @RyanHaining 9 лет назад +2

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

    • @MagnificentImbecil
      @MagnificentImbecil 2 года назад +2

      We all know very well what he meant -- a reference to const --, so we can mentally substitute. This is 90-minute talk with a thousand details. Some typos sneak in. But the meaning is clear.

  • @keepmefromdecay
    @keepmefromdecay 5 лет назад +1

    So is there a similar tool for linux ?

    • @MagnificentImbecil
      @MagnificentImbecil 2 года назад +1

      Yes, certainly. In Linux, one can use Virtual Machine to run Windows with the wonderful Windows applications such as Visual C++. He. He, he, he.

  • @VasiliyGalkin
    @VasiliyGalkin 9 лет назад

    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.

    • @mapron1
      @mapron1 5 лет назад

      No, f(sp) could potentially invalidate global pointer, no it's data. If we change global_sp to new pointer value, any local copy of it is unaffected. So local sp pointing to original global_sp location, no problem at all.

  • @TheRevolucas
    @TheRevolucas 7 лет назад

    I don't get it, one guy on panel exclaims std::max is wrong and now they saying std::min is wrong.

    • @Danielle_1234
      @Danielle_1234 7 лет назад +1

      It was about trying to convert a temporary value (also called: r-value. A variable without a name.) to a reference (also called: l-value reference). C++ doesn't support that.
      Why doesn't C++ support it? Because the temporary (r-value) is by default const. eg func("Hello world");

  • @sienkobilenko
    @sienkobilenko 9 лет назад +1

    Why only VS? Why don't tall about free IDE and what about user of Linux ?)

  • @inyangainyanga1733
    @inyangainyanga1733 9 лет назад +1

    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 );

  • @__hannibaalbarca__
    @__hannibaalbarca__ Год назад +2

    Why old programmers were so smart :
    1. Working with unsafe language
    2. No Social Media
    3. No CS all of them were mathematician.
    So …

  • @LukaszStafiniak
    @LukaszStafiniak 9 лет назад

    Woohoo! Variants!

  • @gim913
    @gim913 8 лет назад +15

    1:09:17 he said eminem, half-life 3 confirmed

  • @ifilmhackersdotcom
    @ifilmhackersdotcom 2 года назад +1

    The community (incl Chandler Carruth, Kate Gregory and even Sutter) came to realize that Modern C++ and in particular move semantics were like lipstick on a pig. It is unusually complex for beginners, it requires much more CS theory knowledge (xvalue/prvalue etc) that should be handled by the compiler like in more contemporary languages as Rust and Carbon. It feels out of place. Many heavyweights are jumping boat, creating new languages due to the realization that Modern C++ hit a dead end.

    • @electricity2703
      @electricity2703 Месяц назад

      There are languages if you don't want to bother these type of stuff, like python etc. I think these stuff make C++ what C++ is.

  • @qumetademo
    @qumetademo 9 лет назад

    Good job

  • @VictorChavesVVBC
    @VictorChavesVVBC 9 лет назад +1

    But C++14 is already out...

  • @llothar68
    @llothar68 8 лет назад +1

    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.

    • @AtheistSid
      @AtheistSid 8 лет назад +2

      +Lothar Scholz multiple return values? Return a struct with multiple members?

    • @llothar68
      @llothar68 8 лет назад

      Karl Hatteland But struct splitting to put the values into variables or pass two result values into another function as 2 seperate arguments is not possible without built in compiler support.
      Yes it is all Syntax Candy and there is a way around it, i know, but then i could also use C and Brainfuck.

    • @twostickman
      @twostickman 8 лет назад +4

      return a tuple, and use std::tie to assign to variables in the calling scope

    • @Baekstrom
      @Baekstrom 6 лет назад +1

      en.cppreference.com/w/cpp/language/structured_binding

  • @sy8111
    @sy8111 9 лет назад

    Good fun

  • @origamibulldoser1618
    @origamibulldoser1618 9 лет назад

    Complaining about heavy annotation in a language that still relies on header files...

  • @childhood1888
    @childhood1888 2 года назад

    32:48

  • @shimondoodkin
    @shimondoodkin 9 лет назад +1

    better name: a better default profile for type safety in c++14

  • @inyangainyanga1733
    @inyangainyanga1733 9 лет назад

    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.

  • @canmetan670
    @canmetan670 8 лет назад +22

    Every time I see an " *auto* " part of my soul dies a little.

    • @mzaxnav4153
      @mzaxnav4153 8 лет назад +3

      (-_-) why? auto is so useful... oh u are talking about auto keyword in C++98.. yeah, that indeed eats part of one's soul.

    • @treyquattro
      @treyquattro 7 лет назад +4

      it's like "var": I don't really know what's going on here so I'll just leave it for the runtime/type checker to figure out. Also it promotes laziness.

    • @NyiBBang
      @NyiBBang 7 лет назад +12

      Wait what ? auto has nothing to do with runtime ...

    • @kamilkoczurek484
      @kamilkoczurek484 7 лет назад +3

      Have you thought that… well, maybe code is a bit cleaner if you use auto instead of std::vector::const_iterator? Writing short and readable code isn't a sign of laziness, it's a sign of being a good developer.

    • @jonesconrad1
      @jonesconrad1 7 лет назад +6

      auto is compile time not runtime. It's not about laziness, it allows much easier refactoring amongst other things. How many libraries I've used where people do something like (int i =0; i < xx.size(); i++) { be_lazy(); } where size() returns a size_t, the compiler then throws a signed / unsigned mismatch warning, can easily be avoided with auto, it's still obvious what you are doing, and if the xx type gets swapped for something where size() returns a signed type, using auto means still no warning. It also prevents copies/conversions of objects where the declared type is mismatched to the assigned value type.

  • @paulfunigga
    @paulfunigga 9 лет назад

    Why are they making it so difficult to use? It's insane, good thing I switched to Java...

    • @iitalics
      @iitalics 9 лет назад +14

      +Paul Orekhov It's safe and VERY fast (much unlike Java...)

    • @paulfunigga
      @paulfunigga 9 лет назад +1

      +Milo Turner that is complete bullshit.

    • @paulfunigga
      @paulfunigga 9 лет назад

      ***** I would, I just don't understand why they have to make C++ so complex, the only thing I like about it is the STL, that's it.

    • @iitalics
      @iitalics 9 лет назад +2

      +Mariano c++ is hardly just object oriented. when they add variants it will be just as functional your average fpl

    • @iitalics
      @iitalics 9 лет назад +4

      ***** because of C++'s history of backwards compatibility, it occupies a niche filled but few other languages. C++ is already widely adapted; rather than being replaced, it is being evolved (whether you like it or not). Most new features aim to replace older, worse features. These features are retained as to not break the large amount of software built on C++; C++ does not have the luxury of quickly deprecating features. Talks like these aim to show how to fully utilize the newer features so that in the future the worse features may be "phased out"

  • @caydnlofton
    @caydnlofton 8 лет назад +3

    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 :)

    • @drazpa489
      @drazpa489 8 лет назад +14

      Not feeling like that at all, to be honest. Also, I'm rarely inclined to people dummies for their mistakes, even though I'd be in a pretty good position to do that. After all, nobody can click on my RUclips-nick to look up a list of the last 20 bugs I fixed in my private code before committing it to some repository, to see if he, in hindsight, could call *me* a dummy. Also, I think I have different opinions on what constitutes "smarties". Devising or adapting an algorithm to solve an actual problem is an exercise that actually requires intelligence. Typing those ideas into some text editor is the least "smart" part of the whole activity. Finding a formal error in memory allocation/deletion doesn't require intelligence and the talk proofs that because they were able to create tools to do that. Wasting the focus and capacity of an intelligent mind on that would be a real dumb thing to do.
      C++ should not be a language that requires smart people who want to get actual hard problems solved (like mathematical problems) to do dumb exercises like reading to thousands of lines to look for memory allocation errors. Because that would make C++ a bad tool. I am happy to see that C++ is becoming a better tool through the great work of people like Sutter and Stroustrup, a tool that allows smart people to get work done effectively, without having to waste their time by gaining hours of experience in questions like "How do I map this list of several hundreds of compiler errors pointing to header-files, I've not even written, to find the single slip I made when using some template?". The tools should help them to use their time more efficiently.

    • @somecoder3054
      @somecoder3054 8 лет назад

      Caydn Lofton exactly what I was thinking. lots of hand holding going on here. not trying to be a spoil sport, it just looks to me to be some bunch of standardising and simplification that might make harder to explain or requiring loads of commenting. as long as they don't actively remove older C++ standards and pointer arithmetic in the future, it's cool but once they start to over it all, that's when it might get ugly, especially for game programmers.

    • @caydnlofton
      @caydnlofton 8 лет назад

      Some Coder Its the age old question: freedom or safety? Freedom to build and design in whatever way is best, even if it takes longer to make sure the code is safe, or safety knowing that a language is there to save you even though it also limits you from exploring

    • @somecoder3054
      @somecoder3054 8 лет назад +1

      Caydn Lofton if the limitations are kept at a minimum with the language allowing for both safe and risky options, then we can all have cake. Give people the options for both and low level interaction. I think that's what most people want anyway

    • @caydnlofton
      @caydnlofton 8 лет назад

      Some Coder Have you heard of C#? :p haha C++ 11 is already very high level programming. But thats just my opinion

  • @childhood1888
    @childhood1888 2 года назад

    55:55