Return to Video

Marijn Haverbeke - The Rust That Could Have Been

  • 0:04 - 0:09
    [ applause ]
  • 0:10 - 0:12
    Yeah, I'm glad so many people
    still showed up
  • 0:12 - 0:15
    at the very end of the conference.
  • 0:15 - 0:20
    So yeah, I'm going to be talking about
    mostly a number of features
  • 0:20 - 0:23
    that were part of the Rust language
    at some points,
  • 0:23 - 0:24
    but no longer are.
  • 0:25 - 0:29
    And, why this is the case
    and usually why this is a good thing.
  • 0:30 - 0:33
    So, as [Ryan?] said I'm Marijn Haverbeke.
  • 0:33 - 0:37
    If you are into Javascript,
    you might have seen my name before.
  • 0:42 - 0:44
    Rust has been under development
    for a while:
  • 0:44 - 0:46
    about ten years now, I think.
  • 0:46 - 0:51
    First - long stretch - was just
    Graydon working in isolation and...
  • 0:51 - 0:55
    Who knows what kind of ideas and
    experiments he abandoned at that point.
  • 0:55 - 0:59
    There's not even a like code repository
    from that time public.
  • 0:59 - 1:02
    so it's like the prehistory.
  • 1:02 - 1:04
    And then, at some point,
  • 1:04 - 1:08
    Mozilla adopted the project
    and assembled a team.
  • 1:09 - 1:12
    From a little before that point,
    we do have Git history,
  • 1:12 - 1:15
    and at that point,
    everything was discussed in issues
  • 1:15 - 1:17
    and mailing lists, and there's...
  • 1:18 - 1:19
    lots of records.
  • 1:19 - 1:23
    I was part of this pretty much -
    the initial team - where we...
  • 1:24 - 1:29
    Moved from the original OCaml-based
    compiler to a Rust-based compiler,
  • 1:29 - 1:32
    and we got a bunch more people
    involved in the language.
  • 1:32 - 1:34
    This was a period of...
  • 1:34 - 1:37
    like, the first real experience
    with the language
  • 1:37 - 1:39
    and a bunch of people
    from different backgrounds...
  • 1:41 - 1:42
    giving their opinions on the language
  • 1:42 - 1:45
    and trying to push it
    into their favorite direction.
  • 1:45 - 1:48
    And, we had a lot of like
    experiments and dead ends
  • 1:48 - 1:51
    and overhauls and false starts and...
  • 1:53 - 1:55
    just lots and lots of churn.
  • 1:55 - 1:59
    We would sometimes come up with
    a breaking change in the morning,
  • 1:59 - 2:01
    and then have a patch ready
    in the afternoon
  • 2:01 - 2:03
    and then convince someone
    to merge it later on and then...
  • 2:04 - 2:08
    Because there was only one codebase,
    we'd just fix everything right away
  • 2:08 - 2:09
    and people could continue working.
  • 2:09 - 2:11
    There was some...
  • 2:12 - 2:15
    some trickiness with actually
    getting like a compiler...
  • 2:16 - 2:19
    that compiles the current code
    after you'd make a breaking change,
  • 2:19 - 2:22
    so you'd first change the compiler,
    then upload a snapshot,
  • 2:22 - 2:23
    then change the code,
    and then you could -
  • 2:23 - 2:26
    everyone could - proceed with
    the new snapshot.
  • 2:26 - 2:29
    And then, of course,
    a year and a half ago - I think -
  • 2:31 - 2:33
    the team [cut] version 1.0,
  • 2:33 - 2:37
    and then the process changed entirely,
    so now it's like...
  • 2:38 - 2:39
    everything stays backwards compatible.
  • 2:39 - 2:44
    It's impressive how seriously they have
    been taking backward compatibility.
  • 2:46 - 2:50
    Experiments moves like -
    [RFCs??] move very slowly
  • 2:50 - 2:52
    and there has to be a wide consensus
  • 2:52 - 2:55
    and it has to fit
    within the current codebase.
  • 2:55 - 2:58
    So, that's a whole different stage again.
  • 3:00 - 3:03
    I'm going to be mostly talking about
    the period where I was part of the team.
  • 3:03 - 3:06
    which was 2011-2012,
  • 3:06 - 3:08
    and which was probably
    the wildest period
  • 3:08 - 3:13
    in terms of features cut,
    features changed - stuff like that.
  • 3:15 - 3:17
    So, it may seem a bit ridiculous
  • 3:17 - 3:20
    that we put so much time into
    really complicated features
  • 3:20 - 3:22
    just to end up dropping them again.
  • 3:23 - 3:28
    But, I think it's kind of an essential
    part of getting a complex design
  • 3:28 - 3:30
    like a programming language right that,
  • 3:31 - 3:34
    unless you're a super-genius,
    you won't really see in advance
  • 3:34 - 3:36
    what the implications
    and the interactions between
  • 3:36 - 3:40
    the various parts of the system are
    and you have to try it and see
  • 3:41 - 3:44
    how well you can make it work
    and how well it fits into the system,
  • 3:44 - 3:46
    and sometimes
    you later have to just...
  • 3:47 - 3:48
    abandon it again.
  • 3:49 - 3:53
    I think that's part of
    a healthy design process for like...
  • 3:54 - 3:57
    mere mortals who need to
    actually see how something works
  • 3:57 - 3:59
    before they can evaluate it.
  • 4:00 - 4:04
    I'm structuring this talk about...
    around a number of visions
  • 4:04 - 4:07
    that were part of the language
    and then dropped again.
  • 4:07 - 4:12
    And, I'll try to explain why I think that,
    in every case,
  • 4:12 - 4:15
    it was a real good decision to drop them.
  • 4:15 - 4:18
    But, it's still interesting to see
  • 4:19 - 4:22
    what the original visions were
    and what we did end up with.
  • 4:23 - 4:28
    So, these are typestate,
    a structural type system and
  • 4:29 - 4:33
    lightweight processes,
    and finally, garbage collection.
  • 4:34 - 4:36
    Let's start with typestate.
  • 4:38 - 4:41
    Typestate is... it was actually
  • 4:41 - 4:45
    an important point in initial
    announcements of the language.
  • 4:45 - 4:47
    and people were very excited about it.
  • 4:48 - 4:51
    What typestate does is basically
    allow you to...
  • 4:51 - 4:56
    allow the compiler to know
    more about value than just its type.
  • 4:56 - 4:57
    So, an example would be...
  • 4:58 - 4:59
    This is something of type [sockets],
  • 4:59 - 5:04
    but we also happen to know that it's open
    or this is something of type array,
  • 5:04 - 5:07
    but we happen to know...
    or say vector in the current terminology,
  • 5:07 - 5:10
    but we happen to know that
    it's not empty.
  • 5:10 - 5:13
    Something like that allowing you to add
  • 5:14 - 5:17
    more safety to your program -
    more static guarantees.
  • 5:19 - 5:23
    So, when you're programming,
    you usually have some mental model
  • 5:23 - 5:27
    of why the thing you are doing
    right now is...
  • 5:27 - 5:30
    is valid - is not going to crash -
  • 5:30 - 5:32
    like if you're not just making
    random changes
  • 5:32 - 5:35
    and seeing if the [tests pass],
    you will have
  • 5:36 - 5:39
    some mental model of your... program.
  • 5:40 - 5:42
    And, to a certain degree,
    depending on the language,
  • 5:42 - 5:45
    you can tell the compiler
    about this model
  • 5:45 - 5:46
    and the compiler can then check
  • 5:46 - 5:49
    whether you are applying
    your model consistently.
  • 5:49 - 5:53
    So, the simple case is just types -
    that you're actually passing the type
  • 5:53 - 5:55
    that you think you are passing somewhere.
  • 5:55 - 5:59
    And, if you don't,
    then, instead of finding out at runtime,
  • 5:59 - 6:02
    you find out at compile time -
    and this is nice.
  • 6:02 - 6:03
    There's a kind of...
  • 6:04 - 6:08
    this computer does not have the fonts
    that my computer had but...
  • 6:08 - 6:10
    Imagine arrowheads on both sides.
  • 6:10 - 6:14
    There's a kind of spectrum
    on which languages fall
  • 6:14 - 6:16
    in terms of how much
  • 6:17 - 6:19
    you can actually communicate
    to the compiler,
  • 6:19 - 6:21
    so down on one side,
    there's Javascript
  • 6:21 - 6:24
    and it's like... syntactically correct.
  • 6:24 - 6:26
    Okay, let's go ahead - let's run it.
  • 6:26 - 6:29
    And then, there's like,
    on the... way on other side,
  • 6:29 - 6:32
    there's language like Coq,
    which require you to actually construct
  • 6:32 - 6:37
    a formal proof that your program does
    what it's supposed to do -
  • 6:37 - 6:40
    that it does so in bounded time,
    in bounded space,
  • 6:42 - 6:46
    which means you're making
    a lot less mistakes.
  • 6:46 - 6:48
    But, on the other hand,
    it's like a major...
  • 6:49 - 6:53
    a major project to write a small program
    in such a language.
  • 6:54 - 6:58
    And, there is a reason that
    not everyone is writing their web servers
  • 6:58 - 6:59
    in Coq or whatever.
  • 6:59 - 7:01
    And, Rust kind of falls in the middle.
  • 7:01 - 7:04
    It does have quite a bit
    of static guarantees
  • 7:04 - 7:06
    and it helps quite a lot.
  • 7:06 - 7:11
    But, it still aims to be ergonomic,
    like easy to [program in],
  • 7:12 - 7:14
    where you don't have to
  • 7:15 - 7:18
    spend too much time
    working on these things.
  • 7:20 - 7:25
    And I... one way to see the history
    of programming languages is kind of...
  • 7:26 - 7:29
    one aspect of it at least is
  • 7:29 - 7:33
    that we've been finding better
    and better vocabulary to...
  • 7:33 - 7:38
    to describe these things we know about
    our program to the compiler
  • 7:40 - 7:41
    in a way that's actually convenient.
  • 7:41 - 7:43
    So, if you have a really terrible
    type system,
  • 7:43 - 7:46
    that's often worse than
    no type system at all.
  • 7:46 - 7:49
    If I have to choose to write something
    in Java or Javascript,
  • 7:49 - 7:52
    I'll just take Javascript,
    thank you very much.
  • 7:52 - 7:54
    But, we're getting better at this,
  • 7:54 - 7:56
    and Rust is making
    a big contribution here,
  • 7:56 - 7:59
    and like bringing a real,
    modern type system
  • 7:59 - 8:00
    to the systems programming space.
  • 8:00 - 8:03
    And the ownership model is - I think -
  • 8:03 - 8:05
    just really, really good.
  • 8:05 - 8:08
    I unfortunately wasn't on the team
    anymore when this was introduced,
  • 8:08 - 8:10
    so I can't take any credit for it, but..
  • 8:10 - 8:12
    I think that this is
    the most exciting part of Rust
  • 8:12 - 8:14
    and it's exactly this kind of thing
    where you...
  • 8:14 - 8:18
    where the compiler knows
    what you're trying to do and
  • 8:18 - 8:21
    tells you when you're
    violating your model.
  • 8:23 - 8:25
    So, back to typestate.
  • 8:26 - 8:28
    It looked somewhat like this.
  • 8:30 - 8:32
    You could define [predicates],
  • 8:32 - 8:35
    which is this "pure function not empty"
    at the top
  • 8:39 - 8:42
    The extra information
    that the compiler had about your values
  • 8:42 - 8:45
    came in the form of this predicate [ ... ]
  • 8:45 - 8:49
    But, these were actually just predicates
    written in normal Rust code
  • 8:49 - 8:50
    that were supposed to be pure.
Title:
Marijn Haverbeke - The Rust That Could Have Been
Description:

This talk will describe a number of language concepts and features that were in the pre-1.0 Rust language at some point but were ultimately abandoned, such as typestate, garbage collection, structural types, and a more or less classical object system. I’ll go over the reasons they were abandoned, and try to convince you that the Rust we have now is the best Rust yet.

---
For more go to https://rustfest.eu or follow us on Twitter: https://twitter.com/rustfest

more » « less
Video Language:
English
Duration:
31:11

English subtitles

Incomplete

Revisions Compare revisions