Rust Programming Techniques

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

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

  • @nathanielwoodbury2692
    @nathanielwoodbury2692 3 года назад +46

    This video was the thing that actually got me to finally understand Rust. I cant say how much this has helped me. I watched every second of it.

  • @daveduvergier3412
    @daveduvergier3412 2 года назад +5

    I think this talk needed to go in earlier discussing move semantics, as otherwise the difference between iterating over Vec vs &Vec is very confusing - the key observation being that IntoIterator *converts* a Vec into an iterator over the T values, such that the original vector is moved out of and no longer available. Most Rust tutorials and books I have seen hand-wave over this stuff in the interests of presenting iteration as super ergonomic, which it is, but I was very confused by this until I worked out what was actually going on

  • @ziliangchen7111
    @ziliangchen7111 6 лет назад +23

    Great talk. May i ask where i can get the slides as ownership is not covered, like to take a look at that piece ?

  • @mohammedtalha4649
    @mohammedtalha4649 6 лет назад +14

    Great Job. Would love to have more in-depth videos such as these focused on application. Would help us adapt rust easily and better correlate to the features of classic programming languages such as C/C++

  • @mikeg9b
    @mikeg9b 5 лет назад +41

    I'm only 14 minutes into this talk, but I'm already picking up on influences from Haskell.

    • @Rene-tu3fc
      @Rene-tu3fc 4 года назад +11

      @Niranjan Raju scala is jhaskell, rust is chaskell

    • @jeffparent2159
      @jeffparent2159 4 года назад

      I love that until I start thinking Haskelly and run into things not in Rust. Why won't they just add GATs and Higher Kinded Polymorphism /rant-over

    • @TheMrKeksLp
      @TheMrKeksLp 4 года назад +2

      @@jeffparent2159 They are coming... eventually. They're super hard to get right that's why they take such a long time

    • @tervaaku
      @tervaaku 3 года назад +3

      I wonder how much of that is from ML, because rust is pretty heavily influenced by ML, the compiler was even original in OcaML

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

    One thing I would have mentioned when covering `.and_then()` at 36:00 is that `and_then()` is just mbind (monadic bind), i.e. the `>>=` operator from Haskell. This becomes pretty obvious when you closely examine its signature, but it was less obvious for me when I first saw it, because of "strange" (but sensible) naming.
    So you can chain functions-which-may-fail with .and_then()s, the same way you can chain promises in js/ts, or the way `do` construct sugars monad bindings in Haskell.

  • @Dygear
    @Dygear 4 года назад +3

    The speaker is phenomenal, and really groks the subject.

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

      makes a lot of sense considering he's working on the team that makes it 😂

  • @krzesimirbonobo6682
    @krzesimirbonobo6682 6 лет назад +16

    Good talk, Nicholas could work on his slides a little bit more though (syntax coloring, side by side code comparison, more meaningful function names etc. and add short 5min intro about language basics)

  • @mybigbeak
    @mybigbeak 6 лет назад +12

    Really enjoyed this viideo. Been looking for a while to find something that went a bit deeper into some details of rust. Thanks

  • @kvadratbitter
    @kvadratbitter 3 года назад +6

    Open question regarding iter() at 37:30
    I’ve just started with Rust and find myself often using iter() to go from result just to get the nice functional methods found on Iter that’s not in Result/Option. It will obviously only iterate 0-1 object so it feels a bit bad/strange to “iterate” it. Is it idiomatic/normal/ok to do this? An alternative would be to make the same code more procedural which I don’t like quite as much.
    Since this is a RUclips comment section I’m sure people has opinions? :)

    • @TheMrKeksLp
      @TheMrKeksLp 3 года назад +6

      Good question! In my experience using Option::iter() or Result::iter() is indeed not the idiotmatic way. And I'm surprised to hear you say that Option and Result don't have similar functional operators because they do! :)
      Option has map, map_or, map_or_else, and, and_then, zip, copied, flatten and many more. In fact, at 30:09 he uses Option::map which is the idiomatic way to model such a thing
      Option: doc.rust-lang.org/std/option/enum.Option.html
      Result: doc.rust-lang.org/std/result/enum.Result.html

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

    great talk from a very knowledgeable speaker! glad he's able to explain to outsiders the great benefits and all

  • @creestooz
    @creestooz 5 лет назад +10

    I think code listing in 46:50 needs a derefernce inside closure `.filter(|x| *x > 1)` or a readable ref '.filter(|&x| x > 1)'

  • @rishabhsharma5050
    @rishabhsharma5050 4 года назад +3

    any follow up video that we can refer to after completing this one?

  • @richard1598
    @richard1598 4 года назад +7

    Does this "wrapping-into-option" hit the performance (i.e., when using iterators which seem to wrap every value into an option just to indicate some end of list)? Or do they somehow get compiled away?

    • @TheMrKeksLp
      @TheMrKeksLp 3 года назад +6

      They're generally as "zero cost" as possible. Let me put it this way: If your function needs to be able to return either something or nothing at all, you obviously need to encode that information somehow. In that case there's no faster option than using Option
      But often they are also just optimized away quite well: e.g. Option has the same representation as a simple pointer to T. Also because predicates and such get "compiled into" the functions they're passed to they are pretty much guarenteed to be inlined. So `iter().map(|x| if x > 1 {Some(x)} else {None}).filter(|x| x.is_some())` will (with optimizations on) never construct an Option object

  • @CrapE_DM
    @CrapE_DM 10 месяцев назад

    I understand why the guy is confused about Result's T and E being in the order that they're in, since most other languages do it in the reverse (likely because of Haskell starting it). My question is why the heck they were in the other order to begin with. I THINK it's because it's inspired by or actually derived from the Either type, where "right" sounds more like it should be the primary type than "left", and so it was made the primary side. But you could have named it "first" and "second" or "primary" and "secondary" or something like that and made it so that the first type listed is the primary type. This has bugged me since the first time I saw it, and I was so proud of Rust for doing the obvious thing.

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

    I'm seeing this for the second time. It's a very good review!

  • @cccPaKYccc
    @cccPaKYccc 6 лет назад +14

    lol, why did they vote traits over ownership?
    difference between functions.methods.traits and functions.methods.methods is easy and could be left as an exercise to the reader. :D
    I can't find the part after the coffee break.
    Anyways, good talk.

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

      Exactly. So frustrating.

    • @gloubiboulgazeblob
      @gloubiboulgazeblob 5 лет назад +2

      Indeed...Understanding Ownership is so basic, so crucial, that it comes BEFORE any fancy thing in Rust !

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

    Does anyone knows where to get the slide of this session ?

  • @cat-.-
    @cat-.- 3 года назад +2

    Knowing how awesome rust really is I feel this person woefully undersells it lol

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

    30 min in and I'm thinking maybe I should learn the language first, before allowing myself to get even more confused.

  • @tanuvishu
    @tanuvishu 6 лет назад +2

    Awesome talk

  • @spheenik
    @spheenik 6 лет назад +2

    Very informative, thanks a lot!

  • @nodehead9475
    @nodehead9475 3 года назад +3

    why are people sitting awkwardly around him LUL

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

    Great talk, badly designed slides although their actual content was good. Some of those slides could be combined (especially comparing C++ vs Rust) so that the talker didn't have to switch between them all the time.

  • @EivindDahl
    @EivindDahl 6 лет назад +10

    This is, kind of like, a good talk

    • @systematicloop3215
      @systematicloop3215 4 года назад +1

      I think it's, kinda like, trying to be like, a good talk, but it kinda like, fails, on like, the communication side of like, things.

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

    nice talk

  • @31redorange08
    @31redorange08 4 года назад +1

    14:57 With “positive”, did you mean non-negative?

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

      what's the difference?

    • @31redorange08
      @31redorange08 3 года назад +2

      @@aykxt 0 is non-negative but not positive.

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

    coool thanks Man

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

    7:30 why would it be mutated? are we talking about a multi-threading app? why is there no mutex/semaphore then?

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

      The thing is not about what should be done, but about what could be done. You should introduce mutexes, but you could go without them out of inexperience or basically any human error. You cannot do it without mutexes in safe Rust.

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

      @@Igigog agree, thanks

  • @rodelias9378
    @rodelias9378 4 года назад +1

    This was really noice!! Thanks! Btw, is the speaker that guy from the Split movie? 😅

  • @thingsiplay
    @thingsiplay 3 года назад +3

    I hate people playing on their phone in a talk. This is very disrespectful.

  • @PaulSebastianM
    @PaulSebastianM 4 года назад +1

    24:44 not err => return err but Err(err) => return err

    • @meow-iskander
      @meow-iskander 3 года назад

      You don't need the return keyword I think

  • @ogal
    @ogal 4 года назад

    Nice content

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

    9:26 troop ready

  • @TheKoffrig
    @TheKoffrig 4 года назад +3

    Monads, monads everywhere

  • @aymanal-qadhi8225
    @aymanal-qadhi8225 3 года назад +2

    Unfortunately, your C++ examples are very misleading. For example, the code you showed at 42:03, could be written in a safer and more elegant form using C++ as the following:
    void ping_all(const std::vector& foos) {
    for (const auto& foo : foos) {
    foo.ping();
    }
    }

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

    Ergonomic? Rust is anything but that. However, the contribution of borrow checking is really significant. Lifetimes? Absolute kludge. This actually motivated me to brush off ANTLR and explore how else this could be handled, as well as polymorphism. The choice between hacks or unending boilerplate is not an attractive one.

  • @CrustyAbsconder
    @CrustyAbsconder 4 года назад +1

    This is just my personal opinion, but I hope it helps you with your presentations. When you are speaking you just way way too many unnecessary words. You speak using the word "like" in places where it is not necessary. You pause and say "uhh," or "uhm" and so, etc. You say "actually" too much. You put in words to exaggerate something, when it is not necessary. That all being said, I can only imagine it is difficult to explain the concepts of rust-code to people that have no idea how rust-code works.

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

      i think.u r missing the entire talk

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

    The talk could have been even more amazing with much better preparation. Speaking in front of audience is a skill and something he should train for, the "uhh" "umm" and all these sounds are quite annoying.
    I still haven't found any good resource explaining the rust's spirit. They all show examples and explain a bit without saying the Why. (yeah mutable variables are bad but all languages have that and it's still working, tell me why it's better instead... and why I just can't use const in C/C++/javascript/... that has the same result)
    They should also stop comparing it with other languages. That's so wrong. It's like learning a new speaking language, at one point you just need to stop translating to your native language to actually learn otherwise you just learn your native language with different words.
    And that also makes the assumption the listener knows those, that isn't always true.

  • @alainterieur5004
    @alainterieur5004 5 лет назад +5

    why are you constantly creating new programming languages
    my brain is too lazy

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

      Fortran68 is all you ever need

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

      @@NoNameAtAll2 I would say C is all you ever need instead

    • @nilstrieb
      @nilstrieb 3 года назад +3

      @@alainterieur5004 C is for people too dumb for assembly, which is for people too dumb for machine code.

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

      @@nilstrieb yes and then you have to rewrite your code for every cpu architectures possible
      big brain

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

      @@alainterieur5004 as I said, most people are too dumb for that

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

    I wish the official rust book was this clear. Instead it feels like it was written by a woman(or a feminine guy) trying to explain you stuff through real world analogies as if you were a child.