Traits and You: A Deep Dive - Nell Shamrell-Harrington

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ค. 2024
  • Traits are one of the most powerful, but also most difficult parts of Rust to master. Come to this talk for a visual exploration of how traits work - from the most basic to the advanced. It is only through deep understanding of a concept like traits that you can fully harness their power in your every day code. You will walk away with a deep understanding of how traits work, why they work the way they do, and the how and why of using them.
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 79

  • @countbrapcula-espana
    @countbrapcula-espana 6 ปีที่แล้ว +123

    She is decisive and speaks extremely clearly and with good force. I like it !!!

  • @sbrugby1
    @sbrugby1 4 ปีที่แล้ว +15

    Tremendous talk. I hope we hear more from Nell in the future. Great communicator.

  • @lerinarazafy7826
    @lerinarazafy7826 6 ปีที่แล้ว +88

    Great teacher. The DnD metaphor should be incorporated into the official Rust book.

    • @macroscalequantumsys
      @macroscalequantumsys 6 ปีที่แล้ว +10

      But using the full rulebook, not simplified.

    • @sunbang9000
      @sunbang9000 5 ปีที่แล้ว +11

      and also a playable demo. ;-)

    • @7xr1e20ln8
      @7xr1e20ln8 4 ปีที่แล้ว +12

      DnD are specific to Western understanding, never learnt about dnd in Asia.

    • @MsHofmannsJut
      @MsHofmannsJut ปีที่แล้ว

      @@7xr1e20ln8 as long as you've played an rpg though...

    • @hanyanglee9018
      @hanyanglee9018 2 หลายเดือนก่อน

      DnD 3r(ust)

  • @jaysanprogramming6818
    @jaysanprogramming6818 6 ปีที่แล้ว +33

    That was awesome! I'd love to see a tutorial series on Rust for newcomers in this kind of format.

  • @xthebumpx
    @xthebumpx 5 ปีที่แล้ว +14

    This is a terrific presentation. Really helped me understand some concepts I had questions about.

  • @webbhinton6842
    @webbhinton6842 3 ปีที่แล้ว +3

    I can not thank Nell enough for this incredibly well done explainer! The DND metaphor really helped.

  • @joelmontesdeoca6572
    @joelmontesdeoca6572 3 ปีที่แล้ว +1

    I wish more Rust talks were like this! The visuals really sold it for me.

  • @scottlott3794
    @scottlott3794 4 ปีที่แล้ว +2

    This is so dense I'm gonna have to watch it like 5 times.. incredible work by the speaker.

  • @gkasten
    @gkasten 5 ปีที่แล้ว +7

    Great introduction, with clear and powerful delivery. Thank you!

  • @konstantinrebrov675
    @konstantinrebrov675 8 หลายเดือนก่อน

    The video game example is really good for understanding traits.

  • @uidx-bob
    @uidx-bob 4 ปีที่แล้ว +3

    Great job! This helped getting me started on wrapping my head around traits.

  • @shailendrajadhav8603
    @shailendrajadhav8603 10 หลายเดือนก่อน

    I came across this video today and I think this is the best explanation of Traits in Rust on the internet!

  • @hardware4200
    @hardware4200 4 ปีที่แล้ว +1

    Just starting Rust, and I was confused about traits, and this pretty much cleared it up, Thanks

  • @amengioio
    @amengioio 5 ปีที่แล้ว +2

    very clear explanation. Thank you for sharing this video.

  • @ProCoder2007
    @ProCoder2007 5 ปีที่แล้ว +4

    Amazing talk. Very clear, entertaining and easy to follow!

  • @yemyint9725
    @yemyint9725 3 ปีที่แล้ว

    This helps me a lot for understanding trait and trait bound which I've been confusing about for a week .👍👍👍

  • @UberOcelot
    @UberOcelot 6 ปีที่แล้ว +9

    On my own, I've basically learned the 101, and 201 sections of this talk. Even some of the 301 section I knew, like how Trait Objects are represented, she doesn't go into the vtables. I always saw Trait Objects as runtime polymorphism, with traits as compile time polymorphism, both forms through composition rather than inheritance. What didn't dawn on me, was the possibility to operate over heterogeneous collections by boxing Trait Objects. That is really cool, and a perfectly example of when to use heap allocation. I like how in Rust you can make these high-level trade-offs that are impossible in most languages.

    • @gabe_owner
      @gabe_owner 6 ปีที่แล้ว

      I agree! I knew it was *possible* to do stuff like the heterogeneous collections w/ vectors of boxed types, but it hadn’t really dawned on me as a common use case.

    • @YourCRTube
      @YourCRTube 5 ปีที่แล้ว

      If you are coming from C++, in C++20 there will be a std::polymorphic_value which will act as Box

    • @yandrosyoutube
      @yandrosyoutube 5 ปีที่แล้ว +6

      Just for the record, Box is not the only way to get Trait Objects and heterogeneous collections. Any kind of (fat) pointer / reference suffices:
      Box but also &Trait, as well as Rc etc.
      And nowadays it is preferred to prefix a Trait name with the 'dyn' keyword to better disambiguate between the trait itself (which is NOT a type) and the dynamic trait object type: Box, &dyn Trait

  • @jaideepganguly
    @jaideepganguly 3 ปีที่แล้ว

    Excellent presentation! Thank you!!

  • @michaelmoore830
    @michaelmoore830 4 ปีที่แล้ว

    This was a great talk. Helped me learn about the Trait objects

  • @ksauri658
    @ksauri658 4 ปีที่แล้ว

    Excellent talk thank you so much!

  • @johnwilliams7999
    @johnwilliams7999 2 ปีที่แล้ว

    I love this video makes it so clear

  • @antanaskiselis7919
    @antanaskiselis7919 5 ปีที่แล้ว +3

    We could really use more of this type of thing!

  • @rodelias9378
    @rodelias9378 2 ปีที่แล้ว

    Thanks a lot for such an impressive talk!!

  • @ShivshankarSharma3578
    @ShivshankarSharma3578 6 ปีที่แล้ว +3

    wonderful explanation.

  • @collinstheweirdo
    @collinstheweirdo 4 ปีที่แล้ว

    Great video, traits were actually quite difficult to wrap my head around at first

  • @androth1502
    @androth1502 5 ปีที่แล้ว +12

    what if the half orc learns to speak elvish on her travels?

  • @Sina-xw4xp
    @Sina-xw4xp 4 ปีที่แล้ว

    Excellent presentation. great job

  • @vic1918
    @vic1918 4 ปีที่แล้ว

    She is amazing, she can teach how to code in PHP and will not be boring.

  • @ianwilson2709
    @ianwilson2709 4 ปีที่แล้ว +1

    great talk, thank you nell

  • @luxiling
    @luxiling 4 ปีที่แล้ว +1

    Fantastic speaker.

  • @jonathanmoore5619
    @jonathanmoore5619 3 ปีที่แล้ว

    Great presentation.

  • @dionysis_
    @dionysis_ 2 ปีที่แล้ว

    Great talk!!

  • @randomuser2579
    @randomuser2579 4 ปีที่แล้ว

    Super nice explanation!

  • @sddkacl2282
    @sddkacl2282 3 ปีที่แล้ว +1

    This is an amazing talk for newcomers

  • @nii-san5485
    @nii-san5485 5 ปีที่แล้ว

    awesome intro to traits

  • @johnsonlease9752
    @johnsonlease9752 4 ปีที่แล้ว

    You got me at cast trait!

  • @aakarshanraj1176
    @aakarshanraj1176 ปีที่แล้ว

    18:41 should be Vec

  • @OdinRu1es
    @OdinRu1es 3 ปีที่แล้ว +1

    Next: how to fight and vanquish the borrow checker with half orc barbarian and elf wizard

  • @friedrichdergroe9664
    @friedrichdergroe9664 4 ปีที่แล้ว +2

    Thank you for this video. It cleared up for me a number of questions I had about Traits -- which are a little like Java's interfaces, but far more powerful. I won't even mention Java! :D

  • @pauloviniciuscoral1128
    @pauloviniciuscoral1128 3 ปีที่แล้ว

    Very informative and inspirational

  • @pratikshares
    @pratikshares 3 ปีที่แล้ว +1

    Doesn't trait objects require `dyn` keyword? Was that added later on?

  • @MMABeijing
    @MMABeijing 2 ปีที่แล้ว

    good job on not laughing each time she said "castrate"

  • @light3rn248
    @light3rn248 6 ปีที่แล้ว +1

    This was indeed a great lecture and she is a great teacher. I wrote everything down while watching the video (easier to follow and understand, especially in 301). In case someone wants to try the "source code", it can be found here: github.com/lightern/rust/blob/master/DD.rs

  • @WindBringsMemories
    @WindBringsMemories 5 ปีที่แล้ว +2

    I think she is a great speaker as well. The only thing that I missed was how the call was implemented behind the scenes. How does the program know which method to call on which "abstract" Cast?

    • @nii-san5485
      @nii-san5485 5 ปีที่แล้ว +6

      Basically, a trait object consists of two pointers (effectively, a "fat pointer"). One part points to the struct memory, the other part points to the impl of the trait for that struct.

  • @sergesolkatt
    @sergesolkatt ปีที่แล้ว

  • @GrandpaRanOverRudolf
    @GrandpaRanOverRudolf ปีที่แล้ว

    isn't it Box

  • @Sina-xw4xp
    @Sina-xw4xp 4 ปีที่แล้ว

    One part that is missing is how to link a character to a spell-book. it is the character that throws the spells not the spellbook.

  • @stevenfletcher3389
    @stevenfletcher3389 2 ปีที่แล้ว

    I think I'm missing the point here. What I took away from this talk is that I can replace a primitive or a Vec with a Trait for no reason. I feel like I understood traits better before I watched this, but everyone else is saying this talk was great. I realize she chose simple examples on purpose, but these are cases where traits shouldn't be used.

  • @peterfarr9591
    @peterfarr9591 5 ปีที่แล้ว

    Great talk! I'll have to say that as for trait objects I've read the two chapters in the book on traits multiple times and I'm not sure the name is appropriate. It's misleading a think because a trait object (unless I'm totally off base) seems nothing like an object in other languages. The implementations themselves are what bring behavior. It's not packaged with the data like in a traditional object. If you "create" a trait object by saying Vec then you aren't creating an object at all. It's more similar to trait bounds the way I see it. You are restricting what the smart pointer (box) points at by defining that it must be something that implements the cast trait. I think the name should be changed maybe, because I think the name 'trait object' is very misleading. If anyone can draw a parallel to traditional objects in other languages to justify the name I'd love to see one. I don't actually think the parallel she drew made sense because we don't package up the pointer with a method in the same location. Am I totally off base here?!

    • @sandipbhattacharya9140
      @sandipbhattacharya9140 5 ปีที่แล้ว

      Traits are, IMO, like interface assignments in Go. You can pass around trait objects like in Go you can pass around interface objects.

    • @SolomonUcko
      @SolomonUcko 4 ปีที่แล้ว +2

      `Box` is a *fat pointer* that contains both a pointer to the data and a pointer to the vtable (virtual table) that has pointers to the method implementations.

  • @hanyanglee9018
    @hanyanglee9018 2 หลายเดือนก่อน

    I'm recently waiting for some dnd or coc game in real life, and, I found one here.....

  • @TheNullBox
    @TheNullBox 3 ปีที่แล้ว +2

    brb... gotta learn D&D first :(

    • @TheNullBox
      @TheNullBox 3 ปีที่แล้ว

      ok never mind.. This is amazing...

  • @CrapE_DM
    @CrapE_DM 6 หลายเดือนก่อน

    I don't get it. How does a typical OO background make traits hard to understand?
    Also, for a "deep dive", this doesn't dive very deep. I was hoping to learn the differences between using generics on a trait and having a type field.

  • @feizhao8878
    @feizhao8878 4 ปีที่แล้ว

    I know rust's OO has its unique. But from what described here, I don't see difference compare to C++ or Java.
    Anybody can make it more explicit, what's the difference.

    • @KohuGaly
      @KohuGaly 3 ปีที่แล้ว +2

      There really isn't one. Traits are basically just interfaces. The difference is mostly historical. Rust uses them by default, consistently, everywhere (especially the standard library) and for every thing, since it started. Unlike in C++ or Java, they weren't added as an optional patch to the (retrospectively obvious) disaster that is the traditional inheritance model.
      The general theme in Rust is that it doesn't really contain anything new. It just has the hindsight of what worked and didn't work in C, C++, Haskel and others and has benefit of fresh start. A lot of stuff that became "standard/recommended practice" in these is the default way in Rust, often enforced by compiler itself.

  • @Posichronic
    @Posichronic 5 ปีที่แล้ว +2

    Who else had their volume turned up when they clicked this?

    • @Samonitari
      @Samonitari 4 ปีที่แล้ว

      Yeah, watching a quiet video beforehand on headphones, clearly reminds you that how important sound-volume normalization SHOULD HAVE BEEN in youtube.

  • @_xeere
    @_xeere 4 ปีที่แล้ว

    she looks like Michael Reeves

  • @7xr1e20ln8
    @7xr1e20ln8 5 ปีที่แล้ว +4

    This is exactly why we need more women in tech, they make things easy to understand.

    • @Itachi.Uchiha.Offical
      @Itachi.Uchiha.Offical 5 ปีที่แล้ว +7

      What the hell does the quality of an explanation have to do with the gender? :D

    • @wiktorwektor123
      @wiktorwektor123 4 ปีที่แล้ว +1

      Some people just have gift to teach and some don't. Gender have nothing to do with it.

    • @MMABeijing
      @MMABeijing 2 ปีที่แล้ว

      vacuous statement. She has high energy and is passionate, that's about that

  • @liptherapy
    @liptherapy 3 ปีที่แล้ว +1

    The naming convention for the trait names is horrible. It would be much more intuitive to use names like in swift protocols. Instead of a Hash trait it would be Hashable. Instead of Cast it would be Castable. It makes type and trait names different. A Hash is something that is a hash of something and Hashable is something that can be hashed.

    • @MMABeijing
      @MMABeijing 2 ปีที่แล้ว

      thank you, ur comment helped me.a.lot. it s obvious now, but.it obvious.now.that.u.mentionned it

  • @edgeeffect
    @edgeeffect 3 ปีที่แล้ว +1

    Too slow and not enough real information.

  • @alexgorodecky1661
    @alexgorodecky1661 5 ปีที่แล้ว +1

    So slow. For little kids?