7 April, 2023

It’s time to learn Rust

The challenge - 100 days of Rust

On the 4th of December, 2022, I set myself the following challenge.

Do at least 15 minutes of programming in Rust every day for 100 days. Today is the 4th of December so that will take me to the 14th of March.

Background

I’d played with Rust about 3 or 4 years ago and had written a couple of command line tools with it. I’d started learning it because I’d heard a lot of buzz about a new systems programming language and I was curious to see how it stacked up against C++. I’d go as far as to say that I really liked the language, but I wondered if it was worth my while to continue with it.

When I heard that a team at my work was evaluating Rust and had even used it for a shipping project, I contacted them, curious to know what they thought. However, it was discouraging to find that there was little appetite for future investment in Rust and that there wouldn’t be any more Rust projects for the time being.

If you don’t work on a large, established codebase then you might ask why a company would be so conservative, but the reality is that companies have to make decisions as to where they invest their time and money. The team perceived Rust as having an immature ecosystem and very few advantages over C++. There are some very experienced C++ devs where I work, and with modern C++, RAII, and a wealth of experience it’s a lot harder to fall into some of the more obvious safety traps.

When people tout the benefits of Rust they often emphasise safety over other language features, and with good reason as Rust certainly has a good story around safety. However, persuading experienced C++ developers to switch to Rust on safety alone is a tough sell when those people have been shipping high quality software in C++ for over 20 years. It also doesn’t help that Rust has a steep learning curve. You may be able to convince a Python developer to choose Rust over C or C++, as C is rather spartan and C++ is a notoriously tricky language to learn. However, you’re going to have a far tougher time persuading an experienced C++ developer that Rust is worth their time.

The perspective from a C++ developer

If you want to persuade seasoned C++ developers to use Rust then you need to use more convincing arguments.

If you’re a Rust developer then this may sound like heresy. But put yourself in their shoes. Imagine yourself writing Rust 20 years from now…

Your company is established and profitable, you’re good at what you do, the language keeps evolving and you continue to keep your multi-million line codebase up to date… and then you keep hearing about a new language whose advocates say that it solves a problem that you’ve largely overcome. And the path to that language isn’t straightforward. Would you switch to this new, untried language on their say-so? Of course you wouldn’t. Why would you?

This sounds negative. It isn’t meant to be. But it’s the perspective that you’ll get from many experienced C++ developers who successfully make a living shipping high quality software to millions of customer devices.

Why give Rust a second chance?

So with that in mind, why give Rust another try? Why not continue to improve my C++ skills?

Well, I do continue to improve my C++ skills. I’m paid to write C++ and I also teach C++ to interns, so I need to be able to explain it. Sometimes I play around with newer C++ features in my free time. And I take advantage of learning days at work to learn more. That’s how I learned how to use C++20’s ranges and views.

But I would be a poor developer if I closed my mind to new ideas. If I’d stuck with the first language that I coded in professionally then I’d still be a Fortran programmer. Yes, I am old. The interns that I teach are younger than my daughter (who is a nascent C++ developer) but I’ve made a good career out of investing in my skills and keeping them relevant.

And as part of that journey, I came back to reconsidering Rust. The question in front of me was, “Should I invest my free time into learning Rust?”

There were two things that answered that question for me.

1) It’s a nice language

Firstly, I had liked Rust when I’d tried it previously. Its move semantics took me a little time to understand as they’re different to C++’s move semantics. And yes, we all know that Rust’s borrow checker can be frustrating at first. But I remembered liking traits very much, and I liked the expressive simplicity of Rust’s iterators. And I appreciated that Rust allowed me to write code with the same peformance characteristics as C++ but without the need for the tacit knowledge of language trivia that is required for C++. What other language has a 275 page book on initialization!

Hint: If you want to persuade C++ developers to use Rust, show them traits. They’re awesome.

2) The market for Rust developers is growing

Secondly, there’s the question of employability. Are there jobs out there for Rust developers? Well, yes, it certainly looks that way, and if the stories in the media about major companies switching to Rust rather than C++ for new projects are anything to go by then it looks like there will be many more opportunities in the future.

Note: I’ve no doubt that one or two of those stories need to be taken with a pinch of salt, because in some of the comparisons they make of Rust vs C++ it is hard to recognise the C++ that they’re talking about. It’s the equivalent of arguing that another spoken language is better than modern English, but making all the comparisons against Shakespeare’s English.

Taking all of that into account, I think we’re now reaching the point where Rust has picked up enough traction for there to be a good market for Rust developers.

Conclusion

In short, Rust is enjoyable to use and there are Rust jobs out there. It’s time to learn Rust.