Long term C++ dev moving to Rust, and my reasons behind the decision.

442 points aerosayan

Hello everyone,

After using C++ for more than 10 years, I'm moving on to Rust.

I'm a founder of a startup for creating High Performance Scientific code, and will be choosing Rust for the following reasons. I hope sharing my experience, will help other developers and teams to decide if Rust is good for their needs, or not.

C++ has been good for me over the years, and as I learn Rust, I would need to keep using C++ for my professional work, as most of my code is already in C++, but with time, I'm definitely going to rewrite all of my code with Rust.

My decision to switch to Rust is motivated by mainly following three reasons ...

​

  1. Safety and correctness when working in a team : I write High Performance Scientific code, and I want my code to be safe. I can more or less write safe code, but when working in a team, it's not possible to hire junior team members who are as good as writing safe code as senior team members. They can write safe code with guidance and experience, but it takes a lot of time to teach them. Rust's memory safety would automatically fix a lot of the bugs that can occur. Rust will also help senior team members, so they can be more productive, as they don't have to worry about writing safe code. The Rust compiler would help them along the way.
  2. Build system and deployment : C/C++'s build system, or lack thereof, is very painful when using third party libraries. It is not uncommon to spend 3-4 days trying to integrate a new library with our build system, as most often the third party library depends on 3-10 other third party libraries, and it often takes a minimum of 3-4 days to just fix all compiler errors, and build the thing. Deploying the code similarly, is very painful, because we have to repeat the same process on a user's computer, and if it fails, we need to fix our own build code to support their OS/Distro/LibraryVersion etc. Linux for example. has too many distros, and supporting build/deployment to all with a simple CMake script is often not possible. It often takes lot of time and resources to just create a single CMake script that works on all OS/Distros. From a management standpoint, this is a continuous waste of resources. Rust solves this with its single build system that works almost everywhere. Being able to pull in third party libraries from cargo, is also a lifesaver, and would allow devs to try out different libraries, and chose one that's best for our task at hand.
  3. Safety and correctness when using third party libraries : I've continued to use C++ for a long time because our own code goes through a severe validation process, and we make sure that it's safe and correct. But often third party libraries have bugs, or we ourselves don't know how to safely use the library, so we cause memory leaks, or data corruption, or race conditions. This is very unique because we don't face the same problems in our own code. Kindly note that I'm not blaming third party devs, but pointing out that it's easy for us to introduce bugs when using third party libraries, because we don't know it well enough to safely use it. Rust, surprisingly, also solves this. The safety issue with third party libraries go all the way down to system driver levels, as just today while using VTK, I possibly found a GPU driver bug that was leaking memory. I've verified that we have a severe memory leak that was OOM'ing the OS, and freezing it, but we have to investigate more if this bug is present in our code (i.e our mistake), or as I suspect, in the GPU driver itself. I hope that as Rust is used more for system driver development, severe bugs like these can be eradicated.

I could probably include a lot more, but from a high level management perspective, these points are the most important for me, and will save us a lot of time while delivering high quality software.

Thanks

​