Introduction to Rust Programming Language

Updated: Mar 26


Credit : Tweets from @oliverjumpertz


What Is Rust? Rust is a systems programming language that is compiled to binary. It has no direct runtime or garbage collector and instead uses a concept called "borrow checking". Developers don't need to explicitly free memory, the compiler does it for them.


The language itself is multi-paradigm, offering functional, generic, imperative, structured, and concurrent programming with a huge emphasis on performance, memory safety, and developer productivity.


According to the Stack Overflow Developer Survey 2021conducted among over 80,000 developers, Rust is the most beloved programming language. And it won the title for the sixth year running.


There are actually quite a few companies now that successfully use Rust. These include Amazon Web Services (AWS), Microsoft, Meta, Dropbox, Atlassian, Coursera


Some Core Features Of Rust


  • Compilation to binary - Rust compiles to binary. When building your software, the compiler does everything necessary to ensure that you get a binary file at the end of the process. This binary isn't platform-independent, but cross-compilation is possible.

  • Memory-safety - The compiler ensures that most of the code you write in Rust's safe subset doesn't leak memory. The compiler and borrow-checker go a long way to ensure that your code is safe, which leads to Rust's steep learning curve.

  • Performance - Rust is damn fast. It's sometimes quicker than C++ and C and sometimes slower. On average, you can place Rust in one bracket with C and C++.

  • Developer-Productivity - Rust has a great toolchain. The compiler has some of the best error messages you have ever seen. The language also comes with its own package manager called Cargo.

  • Resource-efficiency - Rust has (nearly) no runtime and thus no garbage collector. This means that memory does not grow and grow until a limit is hit and the garbage collector kicks in. It only uses what is allocated at a given time. The resulting binaries are also pretty CPU-saving.


What You Can Use Rust For

Rust can be used for a multitude of use cases, and here are some of them:


  • Backend Development

  • Creating CLIs (Command Line Interfaces)

  • Embedded Programming

  • Networking

  • Web Development (through WebAssembly)

  • OS development

  • Blockchain development

I would like to talk a little bit about Blockchain development as this concept is taking the industry by storm.


Although many blockchains nowadays are implemented in C/C++ or Go, Rust is a perfect fit for blockchain development.


The ecosystem has many incredibly well-designed libraries for cryptographic primitives, p2p networking, and more.


The most popular example of Rust's application in blockchain development probably is Solana, closely followed by Polkadot.


Solana itself is implemented in Rust and allows developers to write smart contracts in the same language.


Polkadot is a network protocol that allows arbitrary data—not just tokens—to be transferred across blockchains.


Developers can use the Substrate framework to build their own parachains, implemented in Rust.

Rust Has A Steep Learning Curve

The language is fantastic, but it is a massive shift from what most developers are used to.

As a developer, you really have to think about what you actually do with your variables, where you pass them as an argument, and how you reuse them.


Garbage-collected languages remove the need to think about this from developers.

The runtime and GC simply take care of all memory management.


Learning how to really deal with variable lifetimes can take some time.


Gladly, the compiler has some of the most helpful error messages throughout all compilers that really help you understand what you did wrong, and where. This actually leads to you not having to google everything.


And with time, you get used to it.


And even better, adjusting to the programming style needed and enforced by Rust can improve your code in other languages, as well.

Conclusion

Rust is a great language, and although Go has gained way more traction in recent years,

Rust seems only to have walked a few steps back, to run with even faster speed afterward.

I'm sure that we will hear more and more about Rust being used in different scenarios and by many more companies (including well-known ones).


It might not be suited for all teams or all use cases, but it's usually a valid alternative to consider.

Amazon (AWS) has jumped in and shown huge support for the language. There is even a Rust foundation now that governs all efforts. You don't need to worry that it goes away anytime soon.


35 views0 comments