Rust for Web Developers | Mozilla ♥ Rust

Rust for Web Developers | Mozilla ♥ Rust

May 19, 2019 16 By Bernardo Ryan



let me tell you a little bit about what rust is about rust is a secret weapon rust is a community project Russ's learn from the mistakes of the past rust is a systems programming language that is safe concurrent and fast I've got one word for you rust rust makes systems programming accessible to web developers when you need to optimize your web application instead of diving down 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 nodejs or Python a 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 api's and 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 as 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 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 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 up front 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 you know 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 Java scripts 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 in vetted by others and it makes it incredibly easy to do so by just changing a few little configuration files rust user is 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 and rest 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 JSF 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 and rust you can use neon to plug that in another exciting way that JavaScript programmers are hopefully going to be able to start using rusts pretty soon is by compiling rust to the web using the M scripting compiler with them scripting you can compile your rust app to as MJS 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 programming if you learn super well by reading a textbook go read the rest 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 desk from working directly with other people and from pair programming go find your local recipe cup they're all over the world a great place to look for your first russ code – right as 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 Russ 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 rotation 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 Rex go try rust you