Rust vs. C++

Rust C++ CPP

Teams using C++ often ask themselves, should we switch to Rust or should we keep using C++. Sometimes the also ask me, but I've never written C++ so I would not dare to offer my own thoughts about that.

Instead, on this page I am trying to collect some points one could take in account when comparing the two languages.

There are many articles comparing their technical merits of the two languages, I don't think repeating them here would benefit anyone, though I should link to them. So I look at some other metrics. Some might be relevant to you, some not.

Speed

In general it is said that the run-time speed of the two languages is the same.

Speed of development

This is extremely hard to measure as the level of experience of the programmers has a huge impact on this. The anecdotal evidence is that it might take longer to get the Rust code compile, but then there are a lot less bugs which means the over development and QA time will be shorter and there will be less bugs found after deployment.

Maturity of the language and the ecosystem

Clearly C++ has a huge advantage here. It has been around since 1985 (39 years) while Rust only appeared in 2015 (9 years ago). Rust progresses much faster than C++ for several reasons. It is still in its "early years". It does not have such a huge baggage that requires backward compability and it has a well-designed pas to changes in the language that maintains backward compability while allows the progress of the language.

Number of available programmers

On one hand there are probably a lot more C++ developers with a lot more experience in C++ than Rust developers. On the other hand there might be more people who are enthusiastic about Rust and would like to work in Rust. In The State of Developer Ecosystem 2023 conducted by JetBrains 10% of the developers are likely to adopt Rust, the highest among all the languages, while this number is only 4% for C++ and 2% for C. (On the other hand only 10% used Rust vs. 25% who used C++ and 18% who used C.)

Size of the "community"

Meaning people who are attending Meetups, conferences. There is a separate entry for questions on StackOverflow, and open source developers.

We found 113 Rust user-groups with a combined 65,200 members. (The same person can be in multiple groups so the actual number is lower. Meetup lists 248 Rust groups with a total of 109,982 member, but as far as I can tell for many of those Rust is not the main subject.

I don't have a collection of C++ or C user-groups but Meetup lists 23 C++ groups with 12,664 members.

There a number of Rust conferences every year. I don't know much about C++ conferences. Are there?

StackOverflow

Of course one has to keep in mind that Stack Overflow was established in 2008 and Rust only appeared in 2015 and the number of developers started to grow only then. I think It would be much more useful to compare the number of questions in the last year.

The 2023 StackOverflow survey showed

  • 22.42% use C++
  • 19.34% use C
  • 13.05% use Rust

Reddit

  • r/cpp has 277K members (138 online)
  • r/rust has 286K members (364 online)

Obviously the "number online" will fluctuate a lot, but I checked them at the same time.

There are also other subreddits covering the topics.

LinkedIn

There are several groups on LinkedIn dedicated to C++ developers. These seem to be the biggest ones:

Rust has less groups with less members:

GitHub

  • Rust has 54,558 public repositories
  • C++ has 67,312

One has to be careful with these numbers as these are based on manual tagging of repositories by the project owner.

3rd party (Open Source) libraries

  • Rust has 140,000 Crates.
  • vcpkg, the largest 3rd party registry for C++ has 2,400 packages. There are of course many more packages available around the Internet. One of the difficulties with C++ is that there is no standardized central registry and no easy way to manage the 3rd-party libraries.

Some interesting information related to this topic

Security

Rust has out-of-the-box enforcement of a lot of things for which C++ requires extra tools. I hear many security issues can be detected by the tools available for C++, but those cost money and have a learning curve. The Rust compiler prevents most of those issues entering the code-base in the first place.

Corporations

  • As I understand Microsoft has been switching some projects from C++ to Rust.

  • Rust teams at Google are twics as productive as teams using C++. See video: Lars Bergstrom - Beyond Safety and Speed: How Rust Fuels Team Productivity.

  • Linus Torvalds allows only two languages in the Linux kernel. C, the language that was originally used to write it and recently started to accept Rust as well.

Discussion

There was a long thread on Reddit about this. Some of the comments are quite useful.

Author

Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo