571

February 3rd, 2023 × #Rust#Performance#Beginner

Supper Club × Rust In Action with Tim McNamara

This episode covers the history of Rust, how it aims to be more approachable for new developers, the steep learning curve, good introductory projects like command line utilities and games, performance and efficiency benefits, terminology like crates and cargo, and running Rust via WebAssembly.

or
Topic 0 00:00

Transcript

Announcer

I sure hope you're hungry.

Announcer

Oh, I'm starving.

Announcer

Wash those hands, pull up a chair, and secure that feed bag, because it's time to listen to Scott Tolinski and Wes Bos attempt to use human language to converse with and pick the brains of other developers. I thought there was gonna be food, so buckle up and grab that old handle because this ride is going to get wild.

Announcer

This is the Syntax supper club.

Scott Tolinski

Welcome to Syntax.

Scott Tolinski

We have a really great Supper club today for you. We have Tim McNamara on, and he's gonna be talking all about Rust, the author of The ever popular Rust in Action, which is a mainstay in the Rust community and anybody wanting to pick up Rust. So We're gonna dive deep on all things Rust, and, we're gonna be talking a lot about how it relates to development. My name is Scott. I'm a developer from Denver, Colorado. With me, as always, is Wes Bos. What's up, Wes?

Guest 2

Hey.

Guest 2

Not too much. Excited to talk about Russ. Feels like we've mentioned Russ on the last a 1000 episodes of this podcast. So, I I think 2023 is a big year for it, and I'm excited to learn more. Yeah. Likewise.

Scott Tolinski

Tim, how's it going, man?

Guest 3

You're in, New Zealand? Yeah. That's right. It's stupid o'clock here in, Wellington, New Zealand, Scott.

Guest 3

I, I'm also super excited to talk about Rust. The not only because I happened to notice that one of your goals for the year We're still, like, ship something in Tori, which, I'm I'm Yes.

Guest 3

I'm, I'm pretty excited About the prospect of kind of, like, helping you on that journey. You know, if there are any problems, maybe we can kinda, like, do some live debugging or something. I don't know.

Guest 3

Yeah. No. I have been, in the software space for a little bit of Time now. I actually started as a, as a Python developer in the data science space, machine learning, and natural language processing.

Guest 3

And then over time, kinda developed this itch for kind of figuring out exactly how computers work.

Guest 3

And then eventually, I kind of, like, found my way into this rust space.

Topic 1 02:30

Rust teaches low level computer concepts

Guest 3

And I guess The pitch for the book was that a lot of terminology that the Rust community uses It's kind of, like, all oriented towards this kinda systems programming thing. Like, what what what the hell is that? Yeah.

Scott Tolinski

I know. I did notice that too. Right? It's all about this higher level stuff. Right? And I think people can look at that and say, well, that's Maybe not what I'm interested in. Right. It's like,

Guest 3

is is this interesting? Like, this is not me. Like, I'm a web developer. Right? And so the I I guess The idea was, can I provide some sort of input, to the community that would kind of, like, Not teach you the stuff, but at least kind of give you enough of the knowledge to be able to, like, look through The language and kinda, like, unpick a lot of things so that you don't feel as though you're wearing the wrong clothes And, like, you go to the you go to the event, and it's like, well, I'm really underdressed here? That's an awkward feeling. It's like, well, I Yeah. I don't want People would have come into the Rust community, like, oh, I'm I'm I'm I'm just a web developer.

Topic 2 03:43

Rust in Action aims to make Rust more approachable

Guest 3

That is not the plan. Nice.

Scott Tolinski

Yeah. You know, I I picked up Rust in action a little while ago. I'm, like, one of those Manning sales that they have Black Friday, whatever, and I've just had it for a little while. And it it's one of those ones that everybody talks about is, like, the the thing to pick up if you wanted to learn, Russell. Congratulations on having, like, such a successful Resource.

Scott Tolinski

Was it difficult to write a book like that? Like, especially when at the time, you I don't know if there was a ton of Rust books out that were were especially focused on, you know, practical application.

Guest 3

Right. So to answer your question, It was horrific.

Guest 3

Like, it was actually and this, I mean, it was as funny as it is, like, it was genuinely really difficult. So the the book involved Essentially 4 years work, with all the revisions. It's kind of Like and and the thing about Manning books is that if you pick them up before they're released, you get a chance to kinda, like, talk to the author. And that's awesome from, like, the readership point of view. But, like, from the author, you're, like, getting all these comments from everybody.

Guest 3

And it's like, well, actually, this takes time to respond to. So you're kinda doing customer support while trying to edit your thing. And I would only have, like, a couple hours in the evening. So I try and, like, block out, like, from 8 to 10 PM, 3 or 4 nights a week, plus a chunk on the weekend. Gosh. And you do that and you calculate If you did that for approximately 4 years, which that's, like, 2000 hours.

Scott Tolinski

Just for a book. Right. Right. Right. Well, see,

Guest 3

Why on earth is the book like, why why why why is there so much stuff? And the reason why is that I had this I kinda I did this thing where there there were 2 goals for the book. 1 was to prove to myself that you could write a really technical book, and do it really well. So So I'm kinda noticing this trend that, that TikToks had kinda become, like, content marketing and, like, a little bit of fluff. And I was like, I don't like that. Like, so I really wanna buy write a book that is different, and and really good. And the other thing was, like, I really like examples. Like, I really want to be able to give people a thing that they can take and then expand upon or maybe give a couple of extra features or break and kinda tear apart.

Guest 3

But it turns out that writing software and writing a book is, like, doubly difficult.

Guest 3

And there are, like, 6 of these. Right? So we, like, Database. We write a CPU emulator. We actually go in and say, like, how does your computer how does your computer tell time? Like, what is the network time protocol? And so we, like, write an NTP client, and you connect to at least time servers all around the world, and we do that from scratch.

Scott Tolinski

And you make it Entertaining or enjoyable as as much as well, as much as it can be. Yeah. Yeah. Yeah. So there there's there's, like,

Guest 3

There's a good 5% of people who it just does not land with.

Guest 3

Right? It's like, this isn't like the other books.

Guest 3

Like, why didn't you write this like, why didn't you write, like, this like every other TikTok? But I'd say I'd say Evidence suggests, like, that about 90% of people that read it either really, really like it Or just like it enough that that justifies buying it. And, like, so my goal or the other goal so one was, like, to write this really amazing technical book. It always like to save readers a 100 hours on their learning journey. That was always, always there.

Guest 3

It's worth it for me As someone who's putting in all of this time, if I can get a 1000 people to read it and they can save a 100 hours each, Well, actually, that's like a net gain for the world's productivity.

Scott Tolinski

I love it. Yeah. Absolutely love it. So okay. So You wrote this book on rust. You've clearly been working in rust a long time. When did you first pick up rust, and what what drew you to it? Right. Okay. So

Guest 3

I probably 25 actually, no. The very first time that I encountered it, I spent too much time on hack and use.

Topic 3 08:04

First learned about Rust in 2012

Guest 3

And, there was, there was this thing, like, back in 2012 where Mozilla, like, announced This new language around about the time, and, I the reason why I remember that is because I actually registered the domain name rust.i0, Like, about 6 weeks prior to that public announcement.

Guest 2

Woah. Really?

Guest 3

Yeah.

Guest 3

Yeah. So I I I had this idea that I dude, well, I I was really into writing scrapers, because I and kinda like I kind of had this idea that sometimes the website is the API. I love that. Yeah. Big fan of cigarettes. Yeah. That's very Wes. And then I was like, well, actually, the more that I've worked with these systems, the more that I could, Like, break them.

Guest 3

And so I kind of thought, well, why don't I create, like, a web server, which is kinda like this honeypot thing where you could sit And, like, a hidden you are like, a a hidden link with, like, let's say, like, display, well, I didn't even know my CSS anymore. So I wanna it's like a hidden anchor in the page that a bot would find, but like a human would never click on.

Guest 3

And And you could send people to this kinda crazy thing, which I called Rust, like this corrosive web server.

Guest 3

And I was like, this is this is this is my client's fame. It didn't go anywhere, but I still am paying for the domain name. When I started development, well, I guess, it was about 2015, 2016.

Guest 3

So Hello? The so I was in Python land doing data science stuff, and we would have these big Python, text analysis jobs, I was processing, let's say, dozens of terabytes of text every month.

Guest 3

And The this was a problem because each of our runs would take several hours, and then, like, something would blow up halfway through, which would be like It's It's like a car license. It's a name error. I'm like, there's no name error in here. Like, I am right, Python. Like, what a and then you'd, like, look and be like, oh, no. Python was right. It's like like there really is a bug. Or like, oh, it's like, oh, hello. Today is type aero day. And, no. It's index aero time. The So all of that and so I was like, I really wanted to go fast, and I really wanted to fix this kind of irritating runtime bug problem.

Guest 3

Everyone told me that you should not write native extensions in c. Like, that's for experts. Mhmm. That's, like, dangerous.

Guest 3

Do not write Extensions, n c. Write it, just in just just just make your Python faster. And I was, like, well, actually, kind of unsatisfactory.

Guest 3

You can never bootstrap yourself to, like, an, let's say, expert.

Guest 3

Like, that feels like a very loaded term and, like, how is anyone ever going to learn? And so Rust was what taught me what a pointer was.

Guest 3

Like, rust is the language and the ecosystem and community that made it okay for me to learn And made it okay for me to just be someone that knew about, like, what an like, let's say, like, an array or, like, in Python name, we talk about lists, and in Python, we talk about dictionaries, but in in in, it might just be object in in an array.

Guest 3

And that was kind of it. Like, I didn't really know a lot about sort of fancy data structures and things.

Guest 3

I didn't really care about what was happening, like, on the chip inside my computer. Like Mhmm. Like, the memory didn't really matter To me? Yeah. And now that I program a reasonable amount in Rust, it really matters to me. I look at my Python code, I'm like, what on earth are you doing? But hey. But that's I think one of the things that I like about it in some sense is that it's really it's a technology that has, in the worst case, like a very horrific learning curve. Like, people can kinda like, they're kinda, like, facing the learning cliff, and a lot of people kinda, like, fall off the cliff.

Guest 3

I think that's one of the worst things about the ecosystem is that if you look about the people that have fallen away, About half of those have been people that have just said, you know what? This is way too hard. I just do not get it.

Guest 3

We know that because we, we have community surveys which have a section for people that have actually Still interested in the language, but have, like, decided that they are not part of the like, they didn't they decided to drop the language. Yeah. Let's talk about that for a second. Like,

Guest 2

the approachability of Russ, I'm curious. I think you you kinda went into that. Maybe go a little bit more because, I have never been 1, just a lowly web developer, never been 1 to try to dip my toes into c or c plus plus. Anytime a node module is, a native like, for those who don't know, there's lots of node modules that are written in CC plus plus, and there's just a thin little JavaScript layer to interact with it. And anytime there's one of those, I I throw my hands up, and I say, okay. That's not me. There's no way. But then when we were looking into Tori, I had to write a little bit of rust to to do a little bit of extension stuff, to put some settings in, to make a custom nav. And I was like, Oh, I I don't know, Russ, but, like, I I could I think I could actually do this. Like, do you think Russ is a lot more approachable in that fact? I know you just said people fall off cliffs, but Is it better than other stuff?

Topic 4 13:04

Rust can have a steep learning curve

Guest 3

Right. Okay. So, I just wanna, like, amplify what you just said. The And the other thing that that that really bugged me was that I tried to compile some native extension, and then I get comes crazy linker error. And I'm I do not know What to do here? Like, I do not know how to get myself out of this hole. I don't even wanna touch the code. I just want it to work, and it's not working. So why not? Now is Russ more approachable? And, I really wanna say absolutely, Wes.

Guest 3

Now I like, my but the prob the the the problem that I face is, like like, I am not a like a neutral observer in this discussion anymore. Mhmm.

Guest 3

My impression is that We are getting better at teaching Rust.

Guest 3

So there are some concepts so the syntax is kind of like, it's just a programming language. Right? Yeah. It kind of feels, I there are some there are some really interesting niceties, especially if you have touched c plus plus, that I like. For example, pattern matching and a bunch of there are some things that I really appreciate about Rust, But there are some really irritating bits of, let's say, the semantics. And one of them is this, you kind of encounter this thing like Ownership and lifetimes. And you're like, what is that? And, and also, you encounter some really weird terminology, Like, a trait. Like, I is a trait a class? Like, what what is why is it a trait? Like, is it a Strong type? Like, what is that? And so from my point of or, like, as someone who teaches a reasonable amount of The stuff.

Guest 3

Give me here's my here's my, like, 90 seconds on those topics, if you'll forgive me. Right? So ownership is, not as as poorly named. Russ actually inherited this terminology, so I don't necessarily blame the the the Rust community for this.

Guest 3

But, the Owner is a scope that has, essentially a scope. Let's say it's like a plate I've already muddled things up. That's great. That's a good start.

Guest 3

That, and its responsibility is not to kind of, like, be you it doesn't Get asked for access. It's there to safeguard data. But all it does is when it gets to the end of its scope, It deletes anything that it owns.

Guest 3

So if I'm a variable, Tim, and I've got my buddies Wes and Scott, And I have references to them. So, like and I own them in, like, the Russell view.

Guest 3

When I go out of scope, like, when I go to bed, Those other 2 also need to go to bed.

Guest 3

I don't know if that makes any sense. So that's ownership. No. I think that tracks. Rust variables don't just have a type. They also have a lifetime.

Guest 3

This enables Rust's compiler to guarantee at compile time that, so when you write build, That every single access across the entire on all possible invocations of the language or when it, sorry, of of the program, the the data access will always be valid. So you could imagine let's let's ignore control flow And just say that, a program just is like a sequence of linear steps from, like, 0 to n.

Guest 3

The the Rust compiler can reason that, like, say let's say we we initialize something at at 0.20, And it's alive until 0.30.

Guest 3

Thinks other parts of the program can only reference the variable If

Guest 2

they also exist within, like, those 2 time stamps. So that's, what a live type is. Is that kind of like like type checking in TypeScript where You're not allowed to write code that can reference something that doesn't exist in that scope, but it it it takes a step further and, like, literally, this thing might not exist in memory when you call it, and Rust will stop you from writing code like that? Yeah. No. Exactly.

Guest 3

And, it's it's essentially like Another check. And, in fact, it's even slightly more sophisticated.

Guest 3

So the thing might still exist in memory, But it's been declared as kind of, like, like, no longer in scope.

Guest 3

It's still illegal to access. So you kind of get these weird problems where things kind of linger on in the background in memory, but they're they're actually no longer valid.

Guest 3

But in Rust, that never happens.

Guest 3

This is one of the reasons why I personally believe that Rust is On the accessible productive side, because you actually encounter far fewer kind of runtime bugs that are Irritating.

Guest 3

Really tricky to figure out because once you've kind of gone down the road of relying on access like, being able to refer to another variable, And then you get told later, sorry. That variable was illegal.

Guest 3

Now you've gotta refactor your whole program to fix the bug, And that is kind of super annoying.

Guest 3

The other reason so, like, one of the other motivators of programming Rust is that it's super quick. So you kind of the idea is that, with with, say, like, a JavaScript or TypeScript, like, let's say we're writing things in Node.

Guest 3

We have Node running our JavaScript program and it is what we call interpreting. So it's kind of running alongside our program.

Guest 3

With Rust, the compiler does all of that work upfront, and there's kind of nothing running alongside your program.

Guest 3

Your program gets in the entire, the entirety of the computer all to itself.

Guest 3

And the other part of that is often, Let's say, like, a Go or Java or c sharp or like, name your programming language.

Guest 3

Python, Java, JavaScript, PHP.

Guest 3

Yeah. You'll also find that a lot of them will, like, bolt on, some sort of bookkeeping to your software, which is called a garbage collector. Mhmm. The reason why this happens is because those Programming languages don't have a lifetime.

Guest 3

And so what they do is, like, when you delete something, it's just marked as garbage.

Guest 3

And at some point later, what we call the runtime or the software that is running alongside your program We'll pause your program and just delete anything from memory.

Guest 3

And this is why if you have A program under very heavy load Yeah. You'll sometimes notice latency spikes, like, every couple seconds, And it's in this kinda weird like, it's almost like a metronome going off, like tick tock, tick tock.

Guest 3

You have, like, these really, Big spikes where users just aren't getting the same level of responsiveness from your application, and that's Because the garbage collector is generally under pressure, and it needs to actually stop execution of the rest of the program. Oh, that's I think that was a a really good explanation of garbage collecting beyond what we've ever,

Scott Tolinski

given on this show. So it's because you off We often, in in our world, talk about the garbage collector, or just that process existing. But, to hear it explained that way, I think, was was really nice.

Scott Tolinski

Okay. So let's talk about, like, building things in rust Specifically, if someone like somebody who's a JavaScript developer, they say, alright. I hear everybody talk about rust.

Topic 5 22:02

Good first Rust projects are command line utilities

Scott Tolinski

I want to pick up and try to build something with Rust. I want to explore topics in Rust.

Scott Tolinski

Do you have, like, types of projects that are good introductory to getting some of the the concepts down without necessarily

Guest 3

Destroying someone's confidence. I would start with kind of command line utilities or things that you might run so for yourself, and also something that you actually have probably already implemented.

Guest 3

Because what you don't want is to be learning about, Let's say a problem domain? Like, you don't wanna be exploring the problem while you're also ex like, learning a programming language.

Guest 3

Don't learn 2 or 3 things at once. Don't, like, change your editor at the same time.

Guest 3

Don't be like, oh, look. I also wanna learn, like, this Nix So this thing as well, like, try to take like, pick 1 battle at a time. I like that. Yeah. Implement something you've you already know.

Guest 3

I presumably, also, it might be something that runs Maybe a little bit slower or is a little bit less, but it it it might be a little bit dusty.

Guest 3

It's like Like, it's like you've always known that it's a problem. And then the next step, once you kind of like, you've you've gone through this a little bit, is Picking off, like, bits of projects that are not on the critical path.

Guest 3

You kinda what we're we're we're building up to is, like, we wanna, like, Play with I I recommend games.

Guest 3

Things that are interactive.

Guest 3

Okay. So, one of my hobbies that I'm really, really bad at, But I kinda like toy with is is computer generated art. Oh, cool. Yeah. Things that respond to user input, the UI is often really, really easy. It's just you know, it might just respond to the x, y coordinates of the mouse position, for example, but you have a screen there, and Things are kind of changing because of what's happening underneath.

Guest 3

There are some really mature libraries for playing around with the stuff. And and one's called Bevy, b e v y, that has a very welcoming community Of people that are probably also learning Rust, wanting to learn Rust in a way that that is, kind of interactive And and fun.

Topic 6 24:09

Interactive games are a great way to learn Rust

Guest 3

Then, then someone is gonna say, well, You you the problem with learning Rust is, like, you start talking about it. Everyone's like yeah. It's like, oh my god. No. They've They've got another one. It's like it's kinda like the zombie combo.

Guest 2

Yeah. We lost them.

Guest 3

Yeah. That's right. It's like, oh, no. So, so people are gonna start getting annoyed at you at work because you'll just mention, like, it'd be really good if we could try out rust here.

Guest 3

Like, this would be and, like, you say this enough times, and then people kind of take you seriously. Interesting.

Scott Tolinski

Yeah. It feels like it's a lot like that with a lot of projects. Right? Like TypeScript, For instance. Right? You try it, and it's so exciting. You're telling everybody about it, and everyone's just like, come on. Get a grip.

Topic 7 25:16

Rust provides performance and efficiency benefits

Guest 2

Let let's talk maybe about some of the benefits as well. So we've talked about the benefits on this podcast before. If anyone's listening for the 1st time, they might be thinking, like, What's the point of learning this entirely different language, and why were they talking about this on a, like, a web development podcast? So, like, Why would you ever want to offload all or part of your stack application tooling off to Rust? What's the benefit there?

Guest 3

You, so I have, like a big overarching goal, which is that computing is significantly more environmentally, just, consumes significantly more resources than it needs to.

Guest 3

And, the pitch for me is we can actually create a computing, industry that is significantly more environmentally sensitive.

Guest 3

The reason why we can do that is because apps written in Rust are really quick.

Guest 3

Like and almost, use let's say what does this mean? There was a an article from a company called Tencent That was had a, like, a little proxies metric server thing that they had written in node.

Guest 3

Mhmm. And it was pretty successful.

Guest 3

So they were spinning up, couple 100 or let's say several 100 CPUs to service all of their customers.

Guest 3

They rewrote the thing in Rust and, like, were able to, like, remove hundreds of these machines.

Guest 3

So you kind of have, like, cost Savings is gonna be good for the business.

Guest 3

It's easier to operate from, like, a systems engineering point of view, like, because you've got fewer service to run. But my pitch is, like, that's good for the planet.

Guest 3

Like, I know that's a little bit weird.

Guest 3

But, but but you kind of get this kind of, like, triple threat of the performance improves, so your users are going to benefit.

Guest 3

The business does better because they don't have to spend as much money to get to provide, let's say, the equivalent level of service, And the planet benefits because fewer compute resources are being used. Totally. Like, I I just saw,

Guest 2

the folks from Tailwind were Playing around with rewriting their basically, what they have to do is they have to run through all your template files, and look for tailwind classes. And then And then they look at them, and they they get rid of the ones that aren't in that list.

Guest 2

And right now, it's in node, and they he showed, I think going through 200 template files took 1.1 seconds in node, and 40 milliseconds in Rust, which is twenty 2 times faster, which is unbelievable. Like, you think, oh, a second. But you start looking at, okay, not 200 template files, but What about 2,000 template files or or 10,000 template files? Now all of a sudden, your build is taking 10 seconds when you were just sitting on your hands versus

Guest 3

Less than half a second. It's unreal. Look, every time that you've gotta wait for, like, more than a couple 100 milliseconds, like, it just feels like lag. Like, who enjoys playing a a game with that's laggy? No one not not many people. It gets really frustrating. And I think development is similar.

Guest 3

You kind of you're, editing away, and you hit build, and then you wait.

Guest 3

And what I what I really like is that all a lot of this tooling Is, coming to, let's say, the front end community, and without and it's and it's invisible.

Guest 3

Right. So so no one is going hopefully, not too many people are going to care that their formatter is written in Rust now and not in JavaScript Yeah. Or TypeScript.

Guest 2

But they still get the benefits. That was my next question is, like, in the past, I've had to use Python tools, and I groan every time it needs to happen because it's like, do I have the right version of Python installed? And do I have Python on my server as As well as note like, why is there no Rust hosting? How come I can just, import SWC from an NPM module and compile TypeScript to JavaScript without ever I've never installed Rust on my machine. Like, how is it possible that all of this Rust can run on my computer with me not ever having to do anything?

Guest 3

This works because Rust has is doing a lot of work. What we like, essentially, add build time.

Guest 3

This kinda comes down a little bit to how computers work and how programming languages are implemented.

Guest 3

But, essentially, In Python land, you're sending the script to the server Mhmm. And then asking the server, hey, man. Figure this out for me. It's like, look, I've got all the I've got all the stuff that you need. I've got all of your Python dependencies. Hopefully, they're the right version. Like, I I think that I ran upgrade, and I might have broken a couple of things, but, but Rust will say, okay.

Guest 3

At build time, I wanna bundle all of the dependencies, all of that runtime stuff, into the executable file itself.

Guest 3

And that means that is I I I I'm gonna hit my beats a little bit. But, essentially, you could run like, build for Linux and put it on put your that same file on any Linux machine.

Guest 3

In practice, there's a couple of, like, command line flags that you need to add on.

Guest 3

It doesn't quite work exactly like that by default, And that's because your, Rust compiler is going to say, oh, you're on, presumably, like, let's say, a Mac machine, And you probably therefore wants to have something that runs on Mac that you can't ship over to your Linux server. But with a couple of tweaks, Essentially, we talked about when we talked about the garbage collection thing, we said that there was some, there was some software that was running alongside your application.

Guest 3

With these command line utilities, the executable itself is it contains everything that it needs. There is no you don't Require, like, a node or a Python or, whatever else to actually interpret Your program. You don't send over a script that gets, read in.

Guest 3

What you what you're doing is is sending executable files. So I know that this is kind of, potentially I don't wanna lose too many people here, but I'm gonna give this one a go. Yeah. Do it. Like, what is an executable file? And it's like, well, it turns out that CPUs, all it is is some memory That has been marked by the operating system as executable.

Guest 3

And a CPU is, in some ways, very unintelligent.

Guest 3

All it gets given is some memory.

Guest 3

And it's told, okay, execute that. And so what execution means is interpret the, the memory as numbers and then match those numbers to operations within the CPU.

Guest 3

And so some of those number well, they these are called op codes for operation. So, for example, you could say, like, oh, maybe the pattern Like, the number 50 means addition. So there'll be addition and 2, the 2 things that are being added together.

Guest 3

It turns out that that that, like, Intel and Arm and a bunch of these other CPU vendors have thousands of opcodes.

Guest 3

And, And compilers or people that are building compilers, what they're doing is matching your source code to these opcodes and the And, essentially, just then asking the operating system to feed the stuff to the CPU.

Guest 3

In Rustland or in, like, native extension land, your program takes on the responsibility For ensuring that all of those opcodes are correct, in the previous thing where you might have, like, been asked to, like, Install this Python thing.

Guest 3

What you get is some source code, and you download a version of Python, And you're asking the Python developers to write something that can convert your script to those executable Bobcoats.

Scott Tolinski

Wow. I think that was explained really lucidly.

Scott Tolinski

Like, I I I got that I got that way better than I have before.

Scott Tolinski

So does that mean, like so oftentimes, when we talk about, like, different architectures and CPU architectures, is that, like, if something runs on ARM but doesn't run on this So that does that is that because the op codes between those 2 architectures are different? Is that Yeah. Not anywhere. It it it So, this is like this is, like, warning lights here. Like, there's a big refresher Yeah. I know. This is fascinating. Because,

Guest 3

this is, like, One of the most amazing topics to kinda, like, geek out on. So there's kinda like there's there's no end to the rabbit hole. So this is the warning sign right at the front.

Guest 3

But let's go there. Okay. So, you might I I I just said before that if I compile on a Mac, I can't just send the thing to Linux. This is probably a problem that people live in could and we get these really obscure warnings.

Guest 3

This will become Especially in parents if, like, you have, like, an m one or m two, which is a a Mac, which is an ARM device, And I try and ship the executable binary, like, the file to something that's on an Intel architecture.

Guest 3

So The the terminology that we call is the the, those op codes or matching numbers to operations It's called an instruction set.

Guest 3

And and people refer to an instruction set architecture.

Guest 3

And what they mean is, like, they they kinda totally nerd out on for example, In the ARM world, so what they nerd out on is things like, should all of the opcodes be the same width? Okay. This is gonna sound strange.

Guest 3

But imagine you're a computer, and you need to read in a file and interpret and let and and let's say match the numbers that are there to, like, to operations.

Guest 3

Now if you are Intel, you started in the seventies and there was 8 bit computers.

Guest 3

And one of the things about 8bits is they take 1 byte.

Guest 3

So all of your up codes need to be 1 byte.

Guest 3

And then, like, by the nineties, you have, like, 386, and now you have, like, x8664.

Guest 3

So you have 64 bits For the CPU. And so a, an a 64 bit machine really understands 8 bytes at a time.

Guest 3

Now, Intel still has opcodes that are a single byte.

Guest 3

The Intel computers but it also has opcodes that are 8 bytes wide. So the computer or the the chip actually needs to figure out, like, is this a 1 byte thing or a 4 byte thing or, like, an 8 byte thing? I don't know. I don't know by, like, by definition, like, I'm the thing figuring this out. Whereas an arm machine all has uniform sizes Every single thing needs to I'm pretty sure, summer's gonna rage in the comments that I get this wrong, but I'm pretty sure it's gonna be 4 bytes wide.

Guest 3

Essentially, it's 32 bits.

Guest 3

Or if you are in the figure, 64, but they're all 8 bytes.

Guest 3

So the downside of that so the is that you now are wasting space because things that are super trivial, Let's say, like, addition or some mathematics, a kind of you don't really need all of these opcodes. Right? How many times do we need to We could say, oh, look, we're dividing by an, like, an integer. We're dividing by, like, floating point, but you don't actually Need a lot of sophistication there.

Guest 3

However, Intel has decided that they want to be backwards compatible with every single line of chips.

Guest 3

And so, essentially, every single Intel machine boots up thinking that it's a computer in the seventies.

Guest 3

When it starts, the same the same, like, boot sequence occurs. It's like I start, and all I know is, like, these primitive old opcodes, and then, like, something says, oh, no way. You can now interpret 16 bit.

Guest 3

I can't remember exactly how this happens, but very, very early in the beat the the boot up sequence, You the the the BIOS, I'm pretty sure, tells the CPU, no. No. No. It's okay.

Guest 3

16 bytes are sorry. 16 bits, so 2 bytes are okay. So you're now in the eighties.

Guest 3

And then and then and a little bit further on the boot sequence, it's, like, well, actually, no, no, no.

Guest 3

You're actually 64, bud. Like, it's like hello. It's like it's like, happy birthday. It's, like, you've got some new superpowers.

Guest 3

And, and that was a deliberate decision. They basically took on the technical debt To basically enable their customers to move forward. Now the reason why this is, There are huge amount of engineering trade offs in all of this stuff. So it turns out, by the way, if you really wanna, kind of, like, go completely crazy, You dig in and figure out that these CPUs are sometimes buggy.

Guest 3

Like, CPUs have bugs.

Guest 3

And, that's kinda crazy to think about because they they and, in fact, The CPU has firmware, which you don't have access to as a programmer. You don't even know like Like, even as someone who, like yeah. It it it it's it's really nuts. And so they're actually like, there's a kinda crazy subcommunity of people that find they they hunt for, like, hidden op codes, things that are not documented in the manual that your CPU can do.

Guest 3

Now, I'm seeing Weez's face and, like like, slowly I'm I'm a little bit worried that your listeners are gonna be, like, okay, I'm out. So do we wanna try it? Like, I'm happy to, like oh, no. It's interesting. No. I think this is all fascinating, especially because you don't you know, as web developers,

Scott Tolinski

We write JavaScript, and for a long time. And JavaScript is is really like you're just you're just tossing darts, but you're not even throw in a dart board. You're just throwing them at the wall, wherever. And then TypeScript, you get, like, the little target here. You get you can you can get a little bit more accuracy with what you're doing. And this is, like, really pinpointing things a lot more, which honestly, our our audience and and I don't wanna speak for our audience, but me personally, like, it's super fascinating for me to get this Lower level appreciation.

Scott Tolinski

But, yeah, let's take it back to rust a little bit.

Scott Tolinski

Some some language in in the rust, side of things.

Scott Tolinski

You might hear introductory to rest. You might hear cargo. You might hear crate.

Scott Tolinski

Do do you wanna give a quick rundown? Just 101, what's what what is a crate, and what is cargo and rest? Right. Okay.

Guest 3

A crate is a package, essentially.

Topic 8 40:47

Crates are packages, Cargo is the package manager

Guest 3

So it's kind of the equivalent of running, finding something on NPM Or whichever package manager would you would prefer.

Guest 3

Cargo is the package manager for Rust.

Guest 3

And we came late to, like, the programming language party.

Guest 3

And very early on, They built a good, package manager. In fact, I think the package manager was built by someone who had worked on, the Ruby Gems or the Ruby package manager, and so he had quite a lot of experience with, with kind of Figuring out, like, why this sometimes these really suck.

Guest 3

And so can I so

Scott Tolinski

So and, no, I think because in in JavaScript world, packages and and them sucking or not is a It's a a constant conversation, I think,

Guest 3

our package manager systems? Yeah. So so so so so Rust is actually interesting because it has Actually drawn a little bit of inspiration, I think, culturally from the front end community.

Guest 3

So in the front end community, my impression is, like, this is like this it's like a a crazy circus, just generally. But one thing I quite like about it is that there are, like, Millions of micro packages.

Guest 3

It's like like, people, like, left laugh at left pad, for example. But, in the Rust world, There is a tendency to have lots of specialized dependencies Rather than having, like, a few a smaller number of really big, bulky dependencies, which kind of Was much more the way that things were done kind of in the systems world.

Guest 3

The systems world would say, no. Dependencies are dangerous.

Guest 3

And, essentially, you don't they're kind of like a bad thing. Really, you wanna be able to kind of have Keep everything in house.

Guest 3

And Rust has always been a programming language community that has supported open source and has learned a lot of lessons, I think. One of the lessons that it didn't learn was name spacing.

Guest 3

The cargo is still, like, very early on. Like, In BM, we're, you know, essentially, we're vulnerable to name squatting.

Guest 3

I think, like, a good 20% of the, the crate count like empty packages, essentially.

Scott Tolinski

Mhmm. People just grabbing a name and holding on to it for

Guest 3

Whatever reason Yeah. Domain squaders. Yeah. That's right. It's like, you know, that's a fun name. I I've got a I've got a project idea. I can I'll, Like, I'll backfill that at some stage.

Guest 3

Like, that's the that's the nice way of putting it. But I think the there are also, Like, essentially, domain name squad is inside the Rust community where you have, like, an automated script, like, register 10,000 packages Drizzle something. Oh, wow. Oh, that sucks. If it was that bad, but it was, like, basically, every common word, or, like, someone just went through a dictionary and, like, got them all. Presumably because they wanna receive an email somewhere down the drain of, hey. Can I buy this off you? Yeah. Yeah.

Guest 2

Let's talk about running Rust in different places. Obviously, it can run on Linux and on your Mac and and on Windows, but, it can also run-in other other places as well, including the browser. Have you done anything with running

Guest 3

Rust via Waz? I actually I actually have a talk from, like, the New Zealand JavaScript conference a year or 2 ago. Like like, it's time to oh, what is it entitled? Like, it's time to, like, take a look at web assembly.

Topic 9 44:33

WebAssembly allows running Rust code in the browser

Guest 3

So the if you are Not a lot is gonna be my honest, answer to that. So the WebAssembly is, like, really interesting, but I've actually used WebAssembly more on the server side, which is kind of silly. But browsers Can take a essentially, you can have a dependency

Share