avatarDr. Ashish Bamania

Summary

Google is funding $1 million to the Rust Foundation to improve interoperability between C++ and Rust, highlighting the importance of memory safety and the potential of Rust as a modern systems programming language.

Abstract

Google has announced funding of $1 million to the Rust Foundation to improve interoperability between C++ and Rust, emphasizing the significance of memory safety in programming languages. C++, a popular language used for building backend and embedded systems, has memory safety issues that can cost the tech industry millions of dollars. Rust, a modern systems programming language, offers memory safety without garbage collection, flawless concurrency, a standard compiler with better interpretability, better dependency management, automatic documentation, and other features that make it less error-prone. Despite its steep learning curve and growing community, Rust is being adopted by tech giants such as Google, AWS, and Microsoft, and is being integrated into existing systems. Google has been working on C++/Rust interoperability tools and using Rust in various projects, with the aim of using more Rust in its software systems.

Bullet points

  • Google announced funding of $1 million to the Rust Foundation to improve interoperability between C++ and Rust.
  • C++ is a popular programming language used to build backend and embedded systems, but it has memory safety issues that can cost the tech industry millions of dollars.
  • Rust is a modern systems programming language that offers memory safety without garbage collection, flawless concurrency, a standard compiler with better interpretability, better dependency management, automatic documentation, and other features that make it less error-prone.
  • Despite its steep learning curve and growing community, Rust is being adopted by tech giants such as Google, AWS, and Microsoft, and is being integrated into existing systems.
  • Google has been working on C++/Rust interoperability tools and using Rust in various projects, with the aim of using more Rust in its software systems.
  • Rust is not perfect and can still have logic errors and error handling mistakes, but it is a promising language for writing less error-prone code.

Google Grants $1 Million To Move From C++ To Rust. Is C++ Slowly Dying?

Google Is (Early) Adopting Rust. Are You?

Generated with DALL-E 3

This LinkedIn post recently caught my eye.

Lars Bergstrom’s LinkedIn post (Source)

As per the post, Google announced funding of $1 Million to the Rust Foundation to improve interoperability between C++ and Rust.

This is huge!

Why, you’d ask?

C++ runs the world that we see today.

It is one of the most popular programming languages used to build backend and embedded systems.

According to the TIOBE Index, a measure of the popularity of a programming language, C++ is 3rd on the list (just after Python and C).

C++ is fast, runs with minimal overhead and developers love it.

BUT, programming in C++ comes with a big issue that cannot be left unaddressed.

This issue is — Memory safety.

Are Memory Safety Issues A Big Deal?

Look at the plot from Google’s 2019 report on the vulnerabilities fixed in Android systems.

60% of these vulnerabilities come from memory issues in the code.

Types of Critical and High Severity Vulnerabilities Fixed in Android Security Bulletins in 2019 (Source: Google Security Blog)

That’s the same with most major tech companies:

  • Microsoft: ~70% of the vulnerabilities each year continue to be memory safety issues
  • The Chromium Projects: 70% of the high-severity security bugs are memory unsafety problems (that is, mistakes with C/C++ pointers).

Half of those are Use-after-free bugs (when a program does not clear the pointer to that memory after it is freed).

According to Ryan Levick from Microsoft Azure, in 2004, each memory-related error cost the industry about $250,000.

So, collectively these memory bugs in the C/C++ code costs the tech industry millions of dollars!

Besides the financial costs, malicious actors on the internet exploit these bugs and use them in the commission of attacks against real people.

So yes, this affects the non-programmers at a deeper level than they realise, too.

But Can’t We Fix C/ C++?

A lot of effort has been previously put in to minimise memory-related bugs in C/C++ code.

These include:

But, honestly, none of them have worked well and programmer (human) errors still cause major memory bugs in critical codebases.

Rust To The Rescue

1. Memory Safety Without Garbage Collection

Rust, introduced as a modern systems programming language, introduces Type safety and Thread Safety at compile time.

Unlike C/C++, Rust prevents memory bugs (such as Dangling pointers) through its ownership model without needing a garbage collector.

Eliminating the garbage collector also removes the runtime overhead and makes Rust super fast!

With an ultra-pedantic compiler, Rust won’t let you compile code that violates safety and memory management rules. This drastically reduces the bugs that manifest at run time.

Want a real-world example?

The Authorisation service at npm was recently re-written in Rust and the results? — npm’s first Rust program has caused 0 alerts in its year and a half in production.

Things are so lucrative that Microsoft Azure’s CTO has advised to halt starting any new projects in C/C++!

2. Flawless Concurrency

Unlike C/ C++ which gives developers the responsibility to manage thread safety using locking mechanisms, Rust does so with its ownership and type system again at compile time.

This makes it tough to introduce errors in concurrent systems built using Rust.

3. Standard Compiler With Better Interpretibility

Rust comes with a standard compiler called rustc, which is built using LLVM as its backend.

This allows better optimizations and cross-compilation abilities between different architectures.

Rust compiler errors are also elaborate and extremely helpful, unlike other languages.

This is unlike C++ which has multiple compilers to choose from.

4. Better Dependency Management

Rust comes with a package manager and build system called Cargo and makes dependency management a piece of cake through Cargo.toml and Cargo.lock files.

Cargo automatically downloads and compiles the project dependencies from the Rust package registry called crates.io and simplifies the whole process.

5. Automatic Documentation

Rust has a tool called rustdoc that automatically generates documentation from the comments in the source code.

6. Better Features

Features such as the following also make Rust quite helpful for writing less error-prone code.

  • Immutability by Default
  • Match Statements & Pattern Matching
  • Explicit Error handling with Result and Option enums

To make clear, Rust is not perfect.

A programmer can still write code with logic errors and error handling mistakes, as an example.

Rust also comes with a steep learning curve (with the syntax and principles like Lifetimes), has a steadily growing community of developers (unlike the one established with C/ C++), and is still in the early phases of integrating with existing systems.

But this is being solved by tech giants such as Google, AWS and Microsoft.

Google has long been working on C++/ Rust interoperability tools like:

Some other use cases of Rust at Google can be seen with:

Finally, its 1 million dollar funding is a big step towards its aim of using more Rust in its existing software systems and building new ones!

Although C/ C++ is going nowhere soon, Rust is coming fast to replace a significant chunk.

Are you learning Rust or using it in your codebase? Let me know in the comments below!

Read my other popular Rust-related articles here:

Subscribe to my Substack newsletters below:

Google
Programming
Rust
Software Development
Technology
Recommended from ReadMedium