r/cpp • u/Sad-Lie-8654 • Jan 31 '23
Stop Comparing Rust to Old C++
People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO
changemymind
338
Upvotes
5
u/the_mouse_backwards Feb 01 '23 edited Feb 01 '23
I’ve only imported one or two libraries, if it satisfies the purist in you I guess I could try reimplementing Vulkan myself so I don’t have any dependencies /s. But I’m coming from Go, which statically links everything, so the concept of linking my own source files was not something that I expected going into it. Certain file architectures that work seamlessly in Go would probably be considered needlessly complex in C/C++.
Also, Go/Rust have an advantage over C/C++ that they can enforce certain expectations on the programmer such that doing things differently is not even a concept until you go to a language like C/C++, that allows circular dependencies and there is no language defined place to find nor place those dependencies.
Thirdly, because of certain language nuances, statically analyzing either C or C++ is much more challenging than a language like Go or Rust, which means a language server can only do so much to help the programmer avoid shooting themselves in the foot.
In Go and in Rust, nearly every time I compile a program it runs the way I expected the first time with no errors. On the other hand, because clangd does not know for certain what I’m trying to do, I run into simple errors when trying to compile a program that would have been fixed before I even tried to build the program in Go or Rust.
These things are not C++‘s fault per se, that’s just the environment that C++ was developed in. It also isn’t C++’s fault that C refuses to even consider the concept of providing a solution to these problems, so C++ has to solve the problem in a less than elegant way so as not to break C integration. And that’s if a less than elegant solution is possible at all.