text
stringlengths
0
1.62k
[2402.92 --> 2408.48] of like well i guess there there's a few different kinds of closures and rust is the short version of
[2408.48 --> 2412.46] what i'm saying but the the effect of that is that you can have a closure that basically does
[2412.46 --> 2416.92] represent synchronous stuff and that does that handles the ownership story it handles the borrowing
[2416.92 --> 2420.84] story basically automatically you don't really have to think about what's exactly happening
[2420.84 --> 2425.38] with the closure like you might that you like you might expect from a low level memory managed
[2425.38 --> 2430.34] language and it could do things like oh you didn't capture any variables in this closure so i'm just
[2430.34 --> 2434.06] going to implement it as a regular function with no environment overhead and like stuff like that
[2434.06 --> 2438.78] which is really impressive i think the point is that in like javascript the point i was trying to
[2438.78 --> 2443.56] make is that in javascript a closure is sometimes used for like a loop which can inline everything and
[2443.56 --> 2448.44] just run it right now and sometimes it's used for like a callback and those are basically the
[2448.44 --> 2453.06] same thing in javascript so you can't it's hard to figure out what exactly is going on in rust you
[2453.06 --> 2457.38] can tell you can tell ahead of time like this is a closure that's going to be used later it's going
[2457.38 --> 2461.60] to be used on a thread later so the rules about ownership are more restrictive versus this is a
[2461.60 --> 2466.00] this is a closure that's running right now because it's a you know mapping over an array and that
[2466.00 --> 2469.44] the rules about that are much less restrictive you can basically do whatever you want in there
[2469.44 --> 2475.62] so how do you know the difference do they just look different or context uh so sometimes a lot
[2475.62 --> 2480.78] of it's inferred um some of it is that when you take a closure you can say like for example this
[2480.78 --> 2484.40] is a closure that will only run one time and if it's something's a closure that can only run one time
[2484.40 --> 2488.34] that means you can transfer ownership into the closure uh now the person who wrote the closure
[2488.34 --> 2492.66] doesn't have to think about that the person who takes the closure has to say i'm only going to use
[2492.66 --> 2497.78] this one time right so there's there's a few different uh kind of flavors of closure um and they're
[2497.78 --> 2501.92] mostly described at the at the person who's taking them the person who's calling them just writes a
[2501.92 --> 2506.92] regular closure like you would in ruby and you get exactly the right set of ownership rules that you
[2506.92 --> 2513.12] would want awesome so uh we're gonna move on and talk about some security stuff but i'll just open the
[2513.12 --> 2518.10] open the floor here anything else feature wise that you guys are super excited so i one thing we didn't
[2518.10 --> 2525.70] talk about at all which is kind of mind-blowing to me is the type system um so i i i wrote a lot of ruby
[2525.70 --> 2530.72] in javascript for a long time i pretty much didn't write considerable amount of code with types forever
[2530.72 --> 2536.04] um i don't really like java's type system at all the first few times i had to write java felt like
[2536.04 --> 2541.00] there was a lot of ceremony that's not to say rust doesn't have ceremony of course of course any
[2541.00 --> 2545.46] language of the type system does but one thing that i really like about rust type system is that
[2545.46 --> 2551.32] it takes from a lot of sort of what is well known about expressiveness to get to a point where
[2551.32 --> 2557.38] and and this is still sort of a someday thing but you can see a world where the expressiveness of
[2557.38 --> 2561.04] what you can do with the rust type system is pretty close to the expressiveness of what you can do with
[2561.04 --> 2567.46] a dynamic language um while being totally uh safe and fast and my favorite example of this is
[2567.46 --> 2572.28] in a dynamic language when you write code that's polymorphic in other words let's say you take a
[2572.28 --> 2577.80] function you take something and you call to string on it that to string is just looked up at runtime and it
[2577.80 --> 2580.98] calls the right to string that's what polymorphism is all about right
[2580.98 --> 2585.10] um in rust what you would do is you would say something like i take a function that implements
[2585.10 --> 2590.74] to string and so far that's not that interesting java has that uh you know go has interfaces but
[2590.74 --> 2594.96] in rust the normal way that you say i take a function that implements to string uh what that
[2594.96 --> 2599.52] does is every single time you call it it creates an optimized function that is optimized for the exact
[2599.52 --> 2604.70] uh for the exact type that you've called it with and so instead of it going and looking up at
[2604.70 --> 2608.94] runtime and trying to find that to string function which has some costs and also eliminates inlining
[2608.94 --> 2613.92] right if you have to look something up at runtime you of course can't inline it uh in rust you you're
[2613.92 --> 2618.00] getting a specialized version of that function for exactly the the thing that you called it with this
[2618.00 --> 2623.00] called monomorphization and what that means is that not just that you avoid the overhead of going and
[2623.00 --> 2627.84] finding the function but that you can inline and that's actually how uh steve's trick with calling
[2627.84 --> 2631.88] dot map on an iterator and having that inline all the way to an to assemble to the right kind of
[2631.88 --> 2636.86] assembly the way that that works is that every step of the way you're actually calling functions that are
[2636.86 --> 2641.42] uh that are generic and they're implemented in a way that's very easy to to write specialized
[2641.42 --> 2644.90] versions so you write the specialized version but that now that you have a specialized version you
[2644.90 --> 2648.58] can apply other optimizations and by the time you're done writing running all the optimizations
[2648.58 --> 2654.46] you have something that's as fast as writing it by hand which is pretty nice okay one more point on
[2654.46 --> 2659.24] security i know you know the whole point is safety plus speed i want to ask one question about
[2659.24 --> 2663.30] security and then we'll move on to some other stuff because we're uh we're cruising right along here
[2663.30 --> 2669.66] the whole point is that we can't shoot ourselves in the foot with memory management is it a panacea
[2669.66 --> 2676.74] using rust can you just feel 100 safe or can you still possibly you know write some code that's
[2676.74 --> 2682.94] going to be exploitable so not every error is a memory safety error right so rust's definition of
[2682.94 --> 2688.52] unsafe is very careful to talk about memory safety only and that means that like rust applications will
[2688.52 --> 2693.18] definitely invariably have security issues it's not perfect that said it does address the
[2693.18 --> 2698.94] vast majority of significant like terrifying secured errors because the biggest ones are usually
[2698.94 --> 2704.40] memory safety related or i mean that means segfault right so like if you can segfault then you're
[2704.40 --> 2708.68] talking about a memory safety error right so that's a very common way to get remote code execution is to
[2708.68 --> 2712.96] have a segfault and then you know or stack overflow and like a kind of shenanigans and like it just you
[2712.96 --> 2717.88] know that's not going to happen in rust code um but there are other kinds of errors that can cause
[2717.88 --> 2723.12] problems and you know we don't we don't necessarily although we do try to help with that you know no
[2723.12 --> 2728.92] nobody's perfect right i mean i think it's it's worth i think what steve said is basically correct
[2728.92 --> 2735.76] which is that rust eliminates memory safety issues but i think it's easy to forget how important that
[2735.76 --> 2740.84] ends up being um so most people are used to writing in ruby or javascript and in ruby and javascript
[2740.84 --> 2746.86] you simply cannot segfault unless there's a terrifying bug in your program and in rust that is also true
[2746.86 --> 2751.88] except that in rust you're stack allocating things and have direct control over memory and you don't have a gc
[2751.88 --> 2758.68] and it's honestly like the first until you realize like i just wrote a really complicated thing and
[2758.68 --> 2764.86] it's impossible for the segfault and really think about that it's really hard to to get it but i but
[2764.86 --> 2769.18] i think it's it's it's saying something it's saying something that you can write something that is as
[2769.18 --> 2773.22] complicated as the program you wrote in ruby you didn't have to write any malic or free code
[2773.22 --> 2780.90] and it gets as fat it's basically as fast as well-written c++ code but can't can't segfault
[2780.90 --> 2787.60] can't crash can't have memory vulnerabilities can't out of bounds error right this is you have to like
[2787.60 --> 2795.10] meditate on it to really get it but but just because it feels just because it feels so natural when you're
[2795.10 --> 2798.74] doing it it's like oh i'm used to writing ruby code and i'm writing a closure of course i can't
[2798.74 --> 2802.80] like well it doesn't feel weird except that the thing that you're doing is actually quite weird
[2802.80 --> 2810.12] like the effect is quite strange so you heard earlier in the call you mentioned and i know i've been
[2810.12 --> 2814.10] silent for here for a bit i just know that a lot of this stuff is much deeper than i can go so i've
[2814.10 --> 2820.72] kind of been playing uh back filter uh support but one thing you talked about which uh was pretty
[2820.72 --> 2827.14] important you to mention was the the idea of cargo what role that plays in to crates so you've got
[2827.14 --> 2833.74] crates.io a couple different terms here for new users of rust what do crates what are crates and
[2833.74 --> 2839.68] what role does cargo play in that sure so um as people probably know i worked on the bundler package
[2839.68 --> 2846.64] manager for ruby and the cargo package manager for rust and i think and i obviously use notes i'm
[2846.64 --> 2851.84] familiar pretty familiar with npm and one thing that i think people may have under may underestimate if
[2851.84 --> 2856.72] they're not deeply involved in one of these ecosystems is how important getting a good package
[2856.72 --> 2861.66] management story that makes it easy to add dependencies has been i think bundler helped
[2861.66 --> 2867.64] a lot if people people who didn't use ruby before bundler might forget how few dependencies that were
[2867.64 --> 2872.94] relative to how many there are now and npm also sort of opened the door if you use any npm project
[2872.94 --> 2877.36] you probably have hundreds and hundreds of dependencies i think in ruby it's usually like
[2877.36 --> 2882.94] 50 to 100 dependencies and that that's actually somewhat extraordinary and so uh when i went to work
[2882.94 --> 2886.80] rust one of the first things that i wanted was to make sure that the ideas that came out of
[2886.80 --> 2892.96] bundler and npm basically ideas that would make it easy to have a large a large ecosystem of packages
[2892.96 --> 2898.94] and also to allow a lot of the innovation to happen outside of the standard library that's something that
[2898.94 --> 2902.38] i cared a lot about and there's this is actually a thing that not everyone agrees with right there are
[2902.38 --> 2906.72] programming languages i think python and go are good examples of this where they think it's really
[2906.72 --> 2911.26] really important to have a rich batteries included standard library and mostly uh most of the core