The Changelog: Software Development, Open Source - Intro to Rust programming (Interview)

Episode Date: January 24, 2020

We teamed up with some friends of ours at Heroku to promote the Code-ish podcast so we're sharing a full-length episode right here in The Changelog’s feed. This episode features Chris Castle with sp...ecial guests Carol Nichols and Jake Goulding talking about the strengths of the Rust programming language. Learn more and subscribe at heroku.com/podcasts/codeish.

Transcript
Discussion (0)
Starting point is 00:00:00 What is up everyone? Adam Stukowiak here, Editor-in-Chief of ChangeLog. We teamed up with some friends of ours over at Heroku to promote their podcast called Kodish. You can check it out at heroku.com slash podcasts slash Kodish. Check the show notes for links to that show and how to subscribe. And today we're dropping a full-length episode of Kodish into the ChangeLogs feed. This episode features Chris Castle and special guests Carol Nichols and Jake Goulding, and they're talking about the strengths of the Rust programming language. Here we go.
Starting point is 00:00:38 Hello, and welcome to Kodish, an exploration of the lives of modern developers. Join us as we dive into topics like languages and frameworks, data and event-driven architectures, and individual and team productivity, all tailored to developers and engineering leaders. This episode is part of our Deeply Technical series. Hello, welcome to Kodish. I'm Chris Castle, Heroku Developer Advocate, and this episode is all about the Rust programming language. Rust is often categorized as a systems programming language, but it's really much more capable than that.
Starting point is 00:01:14 And you can see Rust is being used to build web applications, command line interfaces, reimplement JavaScript libraries in WebAssembly when more performance is needed, and even for programming memory-constrained embedded devices. And because of this flexibility and a host of other reasons, Rust is gaining in popularity quickly. I did a quick review of the results of various developer surveys out there, like RedMonk and TiObe, T-I-O-B-E, and they showed Rust as one of the
Starting point is 00:01:42 fastest-growing languages by a number of developers. And even Stack Overflow's developer survey has listed Rust as the most loved programming language for four years running. But personally, I found Rust interesting because it has made low-level programming more accessible to me. I never learned C or C++ when I learned to program 20 years ago. Started in Java and went to Ruby and Node and Python. And Rust has kind of shown me that I can write lower level code,
Starting point is 00:02:10 but still kind of have this like human friendly developer experience or user experience. For sure, Rust has a steeper learning curve than Ruby or Node or Python. But it's tooling, it's documentation, it's community and learning resources out there have made learning it a delightful experience. And that brings me to today's guests. Joining me are Carol Nichols and Jake Golding, who've contributed much to the Rust community. Thanks for joining me, Carol and Jake. Welcome. Let's start with Carol. Can you give us a little intro about yourself?
Starting point is 00:02:43 I'm Carol Nichols. I am the co-author on the Rust Programming Language book. I got interested in Rust. I used to do Ruby and I got interested in Rust because I was working a lot on improving Ruby performance. And there's a point you get to when you really have to, to make Ruby go faster, you have to drop into c but i'm terrified of c and yeah same yeah around that time uh steve kladnick who was and is still a luminary in the ruby world he just kept talking about this brand new language called rust and
Starting point is 00:03:23 how awesome it was so and he actually wrote a book called Rust for Rubyists. And I was like, oh, cool, I can do this. And I started checking out and it was a way to write faster, low resource usage code without the seg faults and the memory problems and use after free and all the problems that come with C. And I was like, oh, this is just what I need. And I started sending Steve a lot of pull requests for his book. And that actually eventually led into me co-authoring the Rust Programming Language book with Steve. Which is kind of like the canonical Rust learning resource. Is that correct? Yeah, we're trying to be. Yeah, it comes with every Rust installation. The book
Starting point is 00:04:11 is on your computer installed with Rust. You can also buy a dead tree version from NoSearchPress. It's not completely comprehensive because Rust is a really big language, but it's aiming to get you productive in Rust and give you what you need to be writing most Rust code. So what about you, Jake? What is your background and kind of entrance into the Rust world? So I kind of came at it from the other direction from Carol. My first big job was a lot and a lot of C code and a little bit of Java, a little bit of Ruby as well. And when I was introduced to Ruby, I was amazed. I was like, this language is so nice to write compared to C.
Starting point is 00:04:52 But I always had that thing in the back of my head where, oh, but what am I giving up by switching to Ruby? And I was introduced to Rust through Carol, and I kind of just took to it immediately. I was like, this is great. This is a wonderful high level language that it's, it allows you to express ideas concisely, but you still get a lot of performance. You have that ability of writing that hardcore C programmer code, but you don't have to give up the things that you normally have to give up when you choose
Starting point is 00:05:25 to write C or C++ code. So that really just kind of rang true for me. And because of my background, I see a lot of similarities of kind of a fusion of C and Ruby. And obviously there's a lot of other influences in Rust. But to me, those two things are kind of like a beautiful marriage and rust is kind of the offspring there yeah that's cool so and and carol mentioned um she and and steve are kind of the co-authors of the rust book um but you also have some kind of pretty pretty major contributions to the rust community um what are some? Yeah, so whatever it is about my brain, I really enjoy answering questions. And so when we started with Rust, it was about Rust 0.13, I think. And at that point in time, there was not a lot of content for it on Stack Overflow.
Starting point is 00:06:19 And I kind of saw my chance. I said, you know, I can get in at the ground floor, I can learn a bunch of things by answering questions. And I might be slightly addicted to answering questions. Definitely addicted. I saw your little pink Kirby character at the top of the list. Yeah. So I'm the number one answerer on Stack Overflow for all things Rust related. And it's really been great for me because I've learned a lot, but hopefully I've also helped a lot of other people learn things. And through that, one of the tools that I end up using the most there is taking people's code and testing it.
Starting point is 00:06:57 And so I would copy and paste a lot of that into the Rust Playground at the time. And over time, I kind of, how Carol started contributing pull requests to the book, I started saying, Oh, well, this part of the playground needs to be better. And this part needs to be better. And I actually ended up re-implementing it. And then now I'm the maintainer of the Rust Playground. But yeah, to back up a little bit, the playground is play.rust-lang.org. And it's a website where you can just type in some Rust code and then send it off to a server that runs it and then spits the output back. So you don't have to have Rust installed to be able to try Rust. And you can share links to programs and things like that. Yeah, big goal of it is to make it so that people who are interested in Rust can very easily see what Rust is, kind of see how the compiler interacts with you and be able to try some things out.
Starting point is 00:07:44 It's obviously a great resource for people trying to report bugs or just communicate ideas. But in my mind, one of its biggest goals is to make Rust really accessible to people who want to try it and don't want to spend the 10 minutes to install it or whatever it takes. So that's great. Interesting stuff that you used to work on in the Rust world. What is kind of the current big Rust project that you used to work on in the Rust world. What is kind of the current big Rust project that you're working on in Rust land? So we've got two things that we've been working on currently. One is the Rust Belt Rust Conference. This will be our fourth year. It's going to be in Dayton, Ohio on October 18th and 19th.
Starting point is 00:08:22 Tickets are on sale now. So we live in the Rust Belt in Pittsburgh and we like showing off that there is technology stuff going on in the Rust Belt. We're no Silicon Valley or New York City or anything like that. But there are a number of us here and there are benefits to being in the Rust Belt. So we've had a conference in Pittsburgh, Columbus, Ann Arbor,
Starting point is 00:08:46 and this year is Dayton. So we'd love to have any of your listeners join us for any levels of Rust knowledge. Jake is actually giving an Intro to Rust workshop on the first day. Yeah, we've done a few conferences over the years, and that's always been a strong component of them is an attempt to make them very accessible to first-time conference goers as well as people who don't even necessarily know the language.
Starting point is 00:09:11 I think you had one more thing that you guys are working on right now, right? A pretty kind of a big project that you've been working on for Rust and Rust education. Yeah, so the second thing we've been working on is the Rust in Motion video series for Manning. It's a video learning course that we're aiming to get you up to speed on the parts that make Rust the most different from most other programming languages. So the topics we cover in the course that we think make Rust the most different, we do a unit on kind of syntax and basic things, things like variables are immutable by default in Rust and the way you call functions and have structs. And the second unit is on
Starting point is 00:10:01 ownership and borrowing, which is a huge difference with Rust that very few languages make an explicit first-class idea. And what this is, is that in Rust, there's one owner of every piece of data. And when that owner goes out of scope, then the data gets automatically cleaned up. So this is the part of Rust that lets you not have to have a garbage collector running while your code is running and cleaning up after you, and also not have to manually think about where you should call free, like you have to in C, which everyone gets wrong and leads to problems like segfaults and use after freeze and things like that. And borrowing is how you can, the owner can let other parts of code use that data without taking over the responsibility of cleaning it up. Most languages don't have that. There are
Starting point is 00:11:01 some that do. C and C++ have concepts of ownership and borrowing. And then the thing that Rust adds on top of that, that is basically unique to Rust, there's a few research languages, is this concept of lifetimes, where the compiler checks and makes sure that the way that you're using this borrowed data is always valid. You're never going to get into a case of memory unsafety. that the way that you're using this borrowed data is always valid. You're never going to get into a case of memory on safety. Where you've borrowed something and then it's been cleaned up, like the compiler makes sure that you aren't doing that.
Starting point is 00:11:41 So all borrows must be shorter than the lifetime of the actual data you're borrowing. So I'm most of the way through the Rust book. I'm actually on, is it lifetime annotations? Is that the correct name? Yeah. Yeah. So chapter 10. Yeah. Yeah. That sounds about right. I'm at the point where I feel like my brain is full or needs more exercises or things like that. So I'm kind of excited to check out Rust in Motion and maybe a few other things to kind of like layer on top of my work through the Rust book so far. One of the goals with Rust in Motion was to cover this different stuff because we've watched a lot of people who are good at picking up new programming languages. Are used to just being able to pick a programming language, pick up the docs and kind of start typing and get into
Starting point is 00:12:25 rewriting their favorite problem and be off and running. With Rust, they try and do that same thing and they hit this brick wall and they kind of freak out because you really have to stop and think and understand what the bar checker is doing and what it's protecting you from and what it's telling you with the error messages. There's been a lot of work put into the error messages and so i think sometimes people are don't read the error messages because they're used to error messages not being helpful but when for us they're actually really great right i think that even those super helpful messages like even if you don't know or if you don't know the terms in that super in that error message it still is you're still going to struggle a bit if you don't know what lifetimes mean or ownership means yeah and carol used the
Starting point is 00:13:08 phrase and it's a common one among the community of fighting the biochecker i understand it i'm always a little disappointed by that choice of words because like the truth is it is the compiler is attempting to help you it's trying to say hey this thing that you are attempting to do could introduce security vulnerabilities to your code hey this thing you're trying to say, hey, this thing that you are attempting to do could introduce security vulnerabilities to your code. Hey, this thing you're trying to do might crash in production. You don't want to do that. And it's really like you're having a nice, well-reasoned discussion with the compiler. With your pair, your pair programmer.
Starting point is 00:13:40 Right. And they're always right. They're right 99% of the time. But the vast majority of the time, they're right. Which can get a little annoying. Yeah. They're right 99% of the time, but the vast majority of the time they're right. Which can get a little annoying. They're really trying to help. Yeah. Jake, you mentioned the Rust community
Starting point is 00:13:52 and there's a fun word or name that's used to describe the Rust community. Do either of you know if there's a story behind that? What is the word, first of all? Is there a story behind where the name came from uh the word is rustation and it's a kind of like crustacean without the c our fun mascot is ferris the crab who is a rustacean um i'm not really sure the origins of it i think we were just looking for a fun name and someone suggested it and then someone drew a cute crab
Starting point is 00:14:27 and there we are. So speaking of the community and kind of other users, what are some examples of kind of interesting uses of Rust or like Rust in production in maybe big deployments or maybe like innovative
Starting point is 00:14:43 or unique or interesting ways. So the most obvious example of rust in production is through Mozilla. It's in the Firefox browser. And it's the most obvious because Mozilla is a huge sponsor of rust. Rust came out of Mozilla research. Yeah. And if you remember two years ago when Firefox released Firefox quantum, and that was the first public release
Starting point is 00:15:05 that had Rust as part of the browser that everyone was running at that point in time. And, you know, they integrated Rust into the, it's called Stylo. It's the part that parses the style sheets and deals with styles inside the browser. And they were able to be very free about using references and especially using references in a multi-threaded context. And because of that, they were able to get pretty sizable speed ups in that portion of Firefox. Now Firefox still has quite a lot of C and C++ code. So it's not by any means all Rust,
Starting point is 00:15:41 but the pieces that they have been able to port to Rust have gotten really sizable and noticeable gains. As you spend many years as a software developer, speed is great and delivering that thing the first time is great, but then maintainability is always a concern, a question, and can be a big problem if it's not kind of planned or thought about what is, or how do people talk about kind of the maintainability story with, with rust? I compare it to C++. It's way better. A big part of that I think is cargo, which is the build management and package manager of rust,
Starting point is 00:16:21 which lets you add dependencies really easily, way more easily than in C++. So that lets you break your program into lots of little components, which can be easier to maintain than one big monolith. And I think the compiler being a constant kind of pair to everyone who works on the code base, i've heard this anecdote from a lot of companies is that more junior developers are you can trust them to write rust because the compiler is always checking that you don't have to review their code quite and frankly with more senior developers too like you don't have to review the code quite so carefully you can review it for
Starting point is 00:17:02 like logic problems which is still very possible in rust. But as far as like the memory things and security vulnerabilities and, and seg faults and crashes, that sort of thing, the compiler. So if it compiles, then, you know,
Starting point is 00:17:17 the compiler has checked all of those things. So it, it makes it a lot easier to bring more people in and more people over time because the compiler is that constant and it really helps out. And to add on what Carol was saying about crates there, Rust definitely is on that side of let's push a lot of stuff into the ecosystem. And there are some people that are not big fans of this concept. My go-to example for this that always kind of surprises people is Rust, the standard library, does not have any mechanisms for generating random numbers. Random numbers is actually offloaded to a, I'll say, third-party crate. It's a crate that's maintained by people that are close to the core ecosystem of Rust, but still it's just a crate that is distributed on crates.io. There's been a lot of work recently in futures, for example, with Rust and all of that work
Starting point is 00:18:10 has mostly been in the third party ecosystem. So there's a lot of do lots of little things. Some of the work from Firefox, like there's a URL crate, and I'm pretty sure that that came out of the Firefox work because they're like you know what everybody needs urls and we are really good at urls because we do web browsers so they're like let's make that public and that's part of that community there is trying to share and trying to have good quality and that's helped i think with maintenance as well just because people are cognizant that this is something that we do. We try to make good quality crates that people can use.
Starting point is 00:18:50 Yeah, so that's cool. Actually, I want to talk more about crates.io. But before that, I want to hear some more examples of other companies or other kind of interesting uses of Rust. Because I think we, like me in the intro in the beginning, and you and I have chatted about CLIs and like embedded devices and all these other different uses for Rust. And I'm curious to hear about some other examples of how those things are being built or who is building those things. Yeah. So a lot of the big end tech companies are using Rust in some projects. Amazon recently announced their Firecracker Micro VM, which is written in Rust. Google is using Rust for their Fuchsia operating system, which they're still kind of secretive
Starting point is 00:19:39 about what they're doing with it, but it's open source. So you can like go see it. Semi-stealth. Yeah yeah so you can see that it's written in rust but we're still not sure what they're doing with it um facebook is using rust for a number of projects they've written a mercurial server in rust that can handle their humongous monorepos they recently announced libra their their blockchain cryptocurrency is written in Rust. And actually, a fun trivia fact, there was recently a congressional hearing where a representative asked an executive from Facebook
Starting point is 00:20:15 about why they were using the nightly Rust compiler and what features they needed the nightly compiler for. This is like a very technical detail and so this came up in congressional testimony because that because they are related to using rust on libra which is aiming to be like a global currency uh rust has proven to be a pretty strong case for blockchain in general there's quite a few projects that are fairly large and fairly mature with regards to blockchain technology. So I think that's a very interesting thing about Rust.
Starting point is 00:20:54 Actually, I thought you were going to say, I thought you were going to mention something about WebAssembly because is Visual Studio Code still an Electron app, which is written in JavaScript? To my knowledge, it is, yeah. I thought you were going to say they re-implemented the search in Rust to make it speedy. Can you speak a little bit more? Do you know of any examples of useful and real examples of Rust and WebAssembly and JavaScript being used? The most real one that I'm aware of, and I don't know exactly where they are in the process,
Starting point is 00:21:30 is the Ember framework has at its core, it's called the Glimmer Engine, I believe. And it's kind of a diffing algorithm. And that that is a piece of that library that is a hundred percent like needs to be performant it's at the core it doesn't touch like any dom really it's all pure data structury i know that there was a lot of effort to get that in rust and then compile the web assembly i don't know exactly how far they are on that. Obviously, with a library like that, you're going to have the issue of WebAssembly is a newer technology. And so if you start making that decision, then you have to have some amount of fallback capability for all the people who may not have a WebAssembly enabled browser for whatever reason. Yeah, I haven't done too much WebAssembly myself, but Rust is one of the few languages that can target WebAssembly.
Starting point is 00:22:33 If you have a choice of what to write your WebAssembly in, I would highly suggest considering Rust. But in general, WebAssembly is a really exciting technology. If people out there have seen Gary Bernhardt's JavaScript talk, I'm not sure if you're familiar. That's not, that's different from the Watt talk, right? Yes, yes. It's a different talk where he predicts that the browser will become the operating system and you kind of run everything within the browser. And that's kind of what WebAssembly is doing. So he kind of predicted WebAssembly in this like joke talk
Starting point is 00:23:10 where he mispronounces JavaScript. It's incredible. One other thing is that even though it's called WebAssembly, the actual virtual machine there is a cross platform and conceptually can be used for lots of different things.
Starting point is 00:23:25 So I've actually also heard of there's a Linux kernel, I believe a module that allows you to write WebAssembly that then gets run inside of the kernel. I think some of the blockchain technologies as well actually use WebAssembly as kind of their base layer for when you're writing blockchain-based applications, they actually get compiled down to WebAssembly. So it's not necessarily WebAssembly is not only the browser, it obviously has web in the name, but it is an assembly language
Starting point is 00:23:58 and can be used in lots of different contexts. Is it the new JVM? That is, I've heard something like that. Because the idea is you've got a set of assembly mnemonics that fit and there are interpreters that you can run it. This time we'll really make something cross-platform. Well, let's jump back to Rust and the cargo utility and crates. And specifically crates.io, which is a project that you're one of the maintainers of, Carol.
Starting point is 00:24:29 Is that right? Yeah, yeah. So crates.io is kind of like the npm.js or the rubygems.org of the Rust world. It's the package registry website for open source packages. The back end is written in Rust. The front end is Ember. And it runs on Heroku.
Starting point is 00:24:53 Nice. That's cool. So many people probably don't know that you can run Rust on Heroku. Rust is, I guess it's not one of Heroku's officially supported languages. No, it's not. We have to use an unofficial build pack. So maybe Heroku can get on that soon since so many other cool people are using it. Maybe you can join us, join Heroku and help be the dedicated language engineer that makes deploying Rust on Heroku a smooth process. It's pretty smooth, even with the unofficial build pack, because the build pack installs Rust, gets the right version, then calls Cargo, which downloads all your pack actually this part is really meta because when we build a new version of crates io it downloads the packages from crates io uh and then builds them and then
Starting point is 00:25:39 uh into into a single executable or actually we have multiple executables but the main server is one executable and then we have a bunch of utilities and then you just kind of run that executable and then your server is running is that using any uh popular rust web framework and if so like what is well i guess in general what are some of the advantages of using rust for an application like this versus using, say, Python or Node or Ruby or Go? Because Rust is so young, there isn't like a Rails for Rust yet. There isn't like one good web framework yet. There's lots of like pieces of web frameworks being worked on and different ideas being experimented with. Crayio was probably one of the first web applications written in Rust.
Starting point is 00:26:26 So it uses this framework that I don't think anyone else uses and no one else should use because it was pretty much written for Crase.io. And it's not even, I wouldn't even call it a framework. It's like barely a small layer over the network code stuff. But there are a bunch of different web frameworks that are kind of, yeah, different stages of maturity and different levels of use. One of the most popular ones is called Rocket. It has a pretty amazing developer experience when you're using it.
Starting point is 00:27:19 Its biggest downside right now is because the maintainer really wants to have such a wonderful developer experience that they require usage of Rust's nightly builds because there are features that they want to use that are not yet stabilized. There's a couple other big ones. So the Rust Playground uses the Iron framework. There's another one. If you've heard of the Tech Empower benchmarks, Rust tends to place pretty highly in those. And one of the ones that does really well there is called Actix Web, which is an actor-based framework built on top of another library called Actix.
Starting point is 00:27:44 With the recent stabilization and continuing stabilization of futures and async await, I think there's going to be a big renaissance in web frameworks and people are looking for things to try, trying these new ideas like Carol mentioned, experimenting to figure out exactly what style works best with Rust code. A lot of the existing frameworks have copied ideas from other languages, which is a great place to start, but then you need to explore within how idiomatic Rust code works, and how does it work in a strongly typed language versus a dynamically typed language, and what is just the right way of putting together these types of apps so i think there's a
Starting point is 00:28:25 lot of that experimentation still going on yeah so if you're if you're looking for like a a real easy smooth kind of rails experience i would wait for writing a web app in rust today if you are excited by experimentation and trying new things and maybe you want to try writing your own and maybe you want to try writing a piece of, like Rails is made up of so many gems. So there's an opportunity for writing a piece of what might become the Rust web framework. So if that sort of thing excites you,
Starting point is 00:29:03 this is a great time to get in and try and experiment. What is, I think in the Rust book, the first like bigger, maybe like non-trivial thing that you have the readers create is a CLI. Is that correct? Yeah. The mini-graph project? Yes. Yeah. It seems like CLIs are a good fit for Rust. Not just in general, but kind of in the state that Rust is at right now also. Are there any CLIs that we would, like I would, or others would recognize that are built in Rust? So RipGrip is one. Right. Yep. Zola is a static site generator that's written in Rust. Oh, yeah. Yep. I think I saw that. Okay. There's like a lot of little ones.
Starting point is 00:29:49 The reason that Rust is a great fit for this is it's cross-compiling capabilities. Whereas if you wrote a command line tool in Ruby, because it's interpreted, you would have to make sure that the person you're sending the tool to has a compatible Ruby version installed. Whereas with Rust, you can cross compile and then just hand off the binaries. Yeah, which we kind of alluded to earlier with deploying of creates IO, but Rust is a, everything gets statically linked at build time. And so when you have this thing, it is just a single executable that you're very likely to be able to pass around.
Starting point is 00:30:26 And I've heard some from people who were writing kind of some smaller tools for like their own companies. And they were like, I actually just checked it out on Windows and it built the first time and I didn't ever think about it until somebody asked if there was one to download. So like, that's a really powerful ability. Now, I mean, you can opt into platform specific things and say, well, I want to make use of something Linux specific or macOS specific or Windows specific. And then obviously, you have to deal with that at some point. But Rust, the standard library is fairly cross platform. And most libraries, except for ones that are specific to a platform, tend to be pretty good at being cross-platform as well. Speaking of cross-platform and cross-compiling,
Starting point is 00:31:13 Rust is also good for writing code for embedded devices. Oh, right, yeah. Jake's actually done way more of that. I mean, so I've played with Arduino and this little device called the ESP8266 and ESP32 that has Wi Fi stuff. Are any of those devices, compile targets, I guess, or the processor on those compile targets for Rust? So the biggest one right now, generally, when people kind of say embedded in Rust, they're talking about the cortex M three arm processor.
Starting point is 00:31:46 That's pretty much the best target right now for rust. Um, to me, like that chip ends up being a little bit more than embedded. It's got all this space. It's got all this, you know, abilities.
Starting point is 00:32:00 Um, I'm interested in Arduino, like you mentioned using the AVR processor unfortunately right now so Rust is built on top of LLVM and LLVM doesn't actually have great support for those chips and so I'm actually part of a project that when I in my copious free time I try to help where they are supporting that inside of LLVM with the intent of getting it into Rust. And so, you know, every few months we update the compiler and try things and figure out where new bugs are. But that's my end goal as well. I think the same thing is kind of true for the ESP that
Starting point is 00:32:39 you mentioned. I think LLVM support for it is not super great. And I think there's another parallel group of people who are working on getting that support as well as getting support in Rust for it. It's funny because most of the work is all in LLVM. Basically, the amount of work inside of Rust to support in your platform, at least for the ones that I've seen, has been very minimal. It's basically tell it what LLVM settings to use and you're 90% of the way there. I mean, one thing that seems interesting too is like, I sometimes think of Raspberry Pi as like not embedded, kind of cheating embedded
Starting point is 00:33:16 because you get this whole Linux environment or OS to work in. But it seems like a $35 Raspberry Pi still has constrained memory, like you're still limited to a gig or actually, I guess, two or four gigs now with the new Raspberry Pi 4s. But, you know, they have GPIO pins, and people do very often use them in projects that are kind of more associated with embedded work. But it seems like that thing still has constrained resources. And so using Rust for those types of projects would still be valuable and useful in using constrained memory, but also efficiently using that CPU that's on the Raspberry Pi. Yeah, and when you start to get into the beefier hardware like you're talking about, there are some operating system projects in rust the most well known is called redox but uh there's actually a really great uh tutorial about creating your own operating system
Starting point is 00:34:13 in rust the person producing is called fill up and i forget if that's their online name or their actual name but you know you could do something like that with the raspberry pi where you basically you are the entire operating system you know that's the best way of getting as much memory as you can right is you don't let anything else run whatsoever but yeah like uh one of the other benefits of using rust for a web service there's some of the white papers on the rust website talk about this but there's web services that were written in java using eight gigabytes of memory or something like that and it was rewritten in rust and now they take on the order of like 50 or a couple hundred megabytes of ram just through the you know ability that you get and so like
Starting point is 00:34:56 that kind of thing would also apply on something like the pi just you'll be able to make much more efficient use of your memory and those resources. And even on Heroku. I used to work for a company that ran a Rails app on Heroku, and there was just a base amount of memory that Rails always needed. And we would hit memory limits, and we'd have to bump up to bigger dynos. And with Crate like i just i sometimes just look at our graphs of memory usage and i laugh because it's just so tiny compared to what a rails app uses the the stat there is that you actually pay more for paper trail for for storing our logs than we do for dynos wow yeah so you can save learn rust save money so we we've talked about some things that Rust is good for.
Starting point is 00:35:47 What are some examples that Rust is not a good fit for? So I think Rust isn't great for prototyping and just writing something real quick that you just want to run once or twice. Or you're doing a demo or you're trying out an idea and then you're going to rewrite it for production later. Like maybe Ruby or Python, Excel in that area. If you're going for pure development speed
Starting point is 00:36:14 and if you want to ignore the things that the compiler is trying to help you remember, then Rust will get in your way a little bit. I think it's good. And I do use Rust to prototype because often prototypes end up in production. But it can get in your way. I think Rust also has kind of that chicken egg thing going on right now. Like, you know, if you want to do some machine learning, right, like hands down, basically
Starting point is 00:36:43 people are going to use something based on top of Python and a bunch of under the hood tools. And so if you want to do that in Rust right now, it may not be pragmatic. Yeah, the ecosystem is definitely still growing in a lot of areas. So it there might not be like in Ruby and JavaScript and Python, like, there's probably a library out there that will do what you want to do. There's probably 10 of them. In Rust, there might be half of one. We'll get there. Right. It's still early. It's always driven by somebody who says, you know, it's almost there if I just put in that little bit of work to get the next thing. Or, wow, if I wrote this in Rust, then I'd get all this other benefits. Let's go ahead and bite the bullet. You know, there's genomics companies out there who are like, you know, we can process that much more data if we
Starting point is 00:37:31 do rust more pervasively than what we're currently doing. Let's go ahead and try and get some of that ecosystem out there. Let's go ahead and, you know, encourage some of these great authors to expand on this or that. Yeah. And, and like, if you, if your code is working, if it's, if you have code written in some other language, it's working, it's doing what you need to do. It's making you money. Absolutely do not rewrite it in Rust. I want to be very clear about that. There are people who go around saying everything should be rewritten in Rust. We disagree with that. When Rust benefits would be useful to you, we encourage you to look at Rust. And there are foreign function interfaces that can help you incrementally rewrite in Rust because wholesale rewrites are always risky. Don't use it just for
Starting point is 00:38:19 the sake of using it. Have a reason to use it. We talked about a few learning resources, but what are some other resources or what's a good path you would share with someone who's interested in learning more about Rust and potentially learning to be proficient in the language? Yes, so we talked about the Rust Programming Language book. There's also Programming Rust is the O'Reilly book, and I've heard they're good complements to each other. So if one doesn't quite resonate with you, the other one might, um, rust in motion video course. If you like video learning more than that, if you like trying out code and learning how to code, there's rust by example, uh, is an official resource. There's also Exorcism, which gives you little programming problems to try and then you submit for review, which is good for lots of languages, but there's
Starting point is 00:39:12 also a Rust track. I started a project a long time ago that I've since kind of passed on to the community called Rustlings. And it's lots of little pieces of Rust code that intentionally don't compile to give you that practice of reading compiler messages and trying to fix them. So you're given this code that's broken and your job is to figure out a way to fix it. I like that. It's easier. It's always easier to like jump into solving problems than to starting with that like blank page that you have to start writing from. There's also the Rust cookbook is kind of trying to be like, I want to parse a URL in Rust. How do I do that? And so it gives you kind of a little recipe of how to do common tasks like that.
Starting point is 00:39:54 For the different areas like the embedded and WebAssembly, there are books just for those areas. So documentation has always been something really important to the rest community. We're really proud of the work that's gone into documentation and that we see documentation as a first-class citizen, as an artifact that we need to produce or else like the technical, if you can't explain how to use something, it doesn't matter how technically great it is.
Starting point is 00:40:24 So we take documentation very seriously. And on that like yeah we talked a little bit about cargo and that's actually part of cargo you know it's a build tool it's a dependency management tool it's also a test runner and it's a documentation build tool and that's all been there since rust 1.0 like These are all things that we take seriously and we say there needs to be documentation. There's actually a lint that you can add in the compiler that will fail your builds if your public API is not documented. And that's something you opt into.
Starting point is 00:40:58 It's opt-in. But it is not unusual to see that in well-regarded crates. One thing that I remember looking for is idiomatic rust. Like I knew I wanted to solve some little problem, but I kind of just wanted like a little bit of a nudge or guidance as to like what is the rust way to do this? And then not only do I know it for that thing, but I can also kind of then repeat that pattern in other places that are similar.
Starting point is 00:41:26 Do you know of any good resources of things like that? Or maybe Rustlings is a good resource for that? Rustlings, I feel like I mostly wrote those to be broken. So I don't know if I'd look to that for good examples. But there is the Clippy tool, which is named after Microsoft's Clippy. It's a set of lints that are not appropriate for the compiler for a variety of reasons. But it will do things like encourage idiomatic code. It does fun things like if it notices you've written
Starting point is 00:41:58 a floating point number that's awfully close to pi, it'll be like, hey, the standard library has this constant for pi you might want to use that instead so it has a lot of hints and nudges and uh checks for things like that and and it can often teach you about uh rust patterns that you don't know about in the realm of idiomatic style there's also um a rust format tool there's a community agreed upon general style for rust and rust format enforces that by default it is one of the configurable tools so if you are strongly opinionated that it needs to be two spaces instead of four spaces or tabs instead of four spaces like it's the kind of thing you can change but
Starting point is 00:42:50 i've been pleased to see that most people who use it tend to stick basically to the defaults which gives a really nice ability to read a random piece of rust code and not have to jump all over with your eyes and that's something that i understand is a touchy subject to a lot of people you know that's my code style don't touch it it. But I'm appreciative that there's mostly a standard. Cool. Well, thanks for joining us for the Codeish podcast. I just wanted to mention Rust in Motion, your video series, video learning series again. And we'll have more details about that in the show notes.
Starting point is 00:43:22 Are you guys still working on that Rust in Motion? It looked like it's like, it's ready to be, to be used and consumed by people, but it's also still like changing and expanding over time. Is that correct? We've finished the first draft of the content. It's still in Manning's early access program. So it still might change a little bit, but all the, all the content is now there. Cool. Well, thanks very much for joining us on Kodish, Carol and Jake. And also, if you want to check out Carol and Jake's video series, the Rust in Motion video
Starting point is 00:43:56 series to learn Rust, we've got a 40% off coupon code here. It's podish19, P-O-D-I-S-H 19, all one word, all lowercase. So yeah, check that out. It'll actually get you 40% off on anything from Man deploy, manage, and scale your applications in the cloud. If you'd like to learn more about Kodish or any of Heroku's podcasts, please visit heroku.com slash podcasts.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.