Rust for Web Developers | Mozilla ♥ Rust

By | March 13, 2020

Let me tell you a little bit about what Rust is about. Rust is a secret weapon Rust is a community project. Rust has learned from the mistakes of the past. Rust is a systems programming language that is safe, concurrent, and fast. I got one word for you: Rust. Rust make systems programming accessible web developers. When you need to optimize your web application, instead of diving to C, which is incredibly error-prone, you can instead use Rust, which is going to protect you from errors and it’s going to be as fast as the hardware allows. There’s a large group of people who traditionally would use higher-level languages like JavaScript or Python or Ruby, that run into performance walls in the code that they’re writing where they need to do something lower level… So something like node.js or Python or Ruby where you might not have all the low-level control to do things like talk to hardware if you’re doing some sort of embedded device or use different APIs or networking protocols that might not be exposed. And one of the promises of Rust is that you can plug it into existing systems, and for the part of your app where you really need to tune the performance up, you can rewrite just that part in Rust. So I think part of the initial promise for people who are just coming to Rust from other ecosystems is they don’t have to jump in with both feet. They can give Rust a try just for portions of their app, and still keep the rest of their app as it is. Rust safe systems programming is a big deal because it brings this kind of programming to the masses, which was never possible before. Rust is about letting people do the same kinds of programming in C and C++ except that when you break, the rules you get an error right away. An automated mentor sitting there beside you saying “Oh, that’s going to end poorly if you write your code that way,” and then not letting you go on until you’ve fixed it. No matter where you are along the learning process you never have to be afraid of shipping code. You don’t have to worry that you’re going to ship code in production and there’s going to be some security exploit, or some segmentation fault because there was some detail of the language that you hadn’t learned yet. When you talk about lower-to-higher level languages, one of the distinctions is that a lower-level language will typically need a whole lot more ‘typing’. ‘Types’ are a way of expressing your intent to the computer so that it can actually check the code you wrote against your stated intentions. JavaScript programmers and Python programmers are not used to having to do that at all. They write the code, and it runs. With Rust you actually have to – it requires you to put in the effort to write out your expectations for what these values are going to be upfront. And the payoff is that you get much better performance and you get much better consistency checking. Rust will catch all kinds of mistakes in your program that a Python system or a JavaScript system wouldn’t catch until you ran your your unit tests. Rust comes with a standard package manager called Cargo, and the entire ecosystem uses it. If you’re coming from JavaScript you’ve probably used a package manager called NPM, and Cargo is essentially the same thing, where it enables it enables you to pull in all this code that has been written and vetted by others, and it makes it incredibly easy to do so by just changing a few little configuration files. Rust users consistently point to Cargo as one of their favorite parts of the experience of Rust programming. We made the conscious decision that it wasn’t enough to just ship a programming language. We needed to also ship a tool that would allow people to share their libraries in a consistent, uniform way. If you want to write OpenGL code, you can just find a library that’s already been written so that you can do OpenGL code in Rust. Quick and easy, and in one place. One of the projects I’ve been working on is a system called Neon that allows you to plug Rust into a Node.js app. So let’s say you have a Node app and you’ve noticed that one part of the app really could stand to be optimized further, and you’d like to rewrite that part in Rust. You can use Neon to plug that in. Another exciting way that JavaScript programmers are hopefully going to be able to start using Rust pretty soon is by compiling Rust to the web using the emscripten compiler. With emscripten you can compile your Rust app to asm.js and you can also compile it to webassembly, which is an emerging standard for high-performance web applications. So, part of what’s exciting about this is it’s giving JavaScript programmers access to the highest performance part of the web platform, and it’s also giving them an opportunity to experiment with Rust, and get started learning how to do Rust programing. If you learn super well by reading a textbook, go read the Rust book from cover to cover. It’s free and online. If you learn better from trying stuff out, find a repo of simple exercises that come with their answers. If you learn best from working directly with other people and from pair programming, go find your local Rust meetup. They’re all over the world. A great place to look for your first Rust code to write is the Servo project, which is building a next-generation web engine, and is a community that’s very big on helping newcomers get started with Rust programming. The way that you will buy this improved performance and this improved safety is going to be with some frustration and some study, but someday you’ll find yourself teaching a new Rustacean about how the language works, how they can make their own trait, how they can debug that particular error and make it go away, and you’ll realize you’ve made it. This is easy now. Come to Rust and you feel like you suddenly have superpowers. I love Rust. Congratulations on starting Rust. Go try Rust.

Leave a Reply

Your email address will not be published. Required fields are marked *