by jasode · 6y ago · 0 comments
Some example domains of libraries & tools where C++ is the 1st class client instead of Rust:
+ deep learning: NVIDIA CUDA api is C++
+ HPC High Perfomance Computing: Intel MKL math library is C++
+ physics engine for video games: Unreal game engine is C++
+ latest cpu chip : ARM Allinea dev tools for the new Neoverse chips (e.g. latest AWS Graviton2 servers) is C++
+ Qt GUI is C++
Because of the extensive C++ ecosystem, you get a non-intuitive situation where programming the latest cutting-edge apps requires a 35-year-old language from 1985 instead of the newer Rust language from 2012. I predict this delta of tools+libraries between C++ and Rust will continue to exist for 10+ years.
One could try to write a bunch of Rust wrappers for all the above C++ SDKs but I'm not convinced that's a good use of development resources.
Embark Studios in Stockholm did exactly that for their open source NVIDIA PhysX wrapper [1].
I can recommend Tomasz Stachowiak's talk about how it was done and how all the compiler-defined behavior was dealt with [2].
35 years of usage means it is a sound language. Nothing non-intuitive there.
Modern C++ is actually quite different from the 35 year old version. For example, you basically do not need new and delete if you stick to the core guidelines. That's a paradigm shift.
The fact that Rust has zero-cost FFI and even inlining across LLVM languages allows you to take existing C/C++ project, and start writing new Rust code on top of it.
It's like a more performant version of what people do with Python. Nobody says "oh, I can't use Python, because my device drivers aren't written in Python".
Almost every feature of C++ is there to make writing powerful libraries possible. Many uses of such features become part of the library interface, because that enables zero-overhead libraries with semantics intricately integrated into the caller's usage.
Rust has a goal of zero-overhead code, but is not designed to minimize the overhead of library usage. That was a choice: it makes the language simpler and easier to learn, but that comes at a cost. You cannot write a Rust library to do what is routinely done in C++ libraries, and a Rust wrapper cannot expose those capabilities to Rust code.
+ macOS, iOS and Android drivers are C++
+ UWP/WinUI is a mix of .NET and C++
+ console SDKs use C++
+ Metal shaders and HLSL are C++ dialects
+ Arduino is C++
+ ARM mbed is C++
Unless c++ makes some major changes I think Rust will gain steam in all the areas you mentioned.
But that's Python, where the language is slow enough that any marshaling costs can generally be dismissed as a rounding error. The practicalities may be different in a shop that is deciding between Rust and C++.
- fully evented with arbitrary number of threads servicing event loops
- straightforward API with examples
- HTTP 1.1/2/3 out of the box
- terminates SSL/TLS out of the box
- extremely hardened
It’s not tiny and header only or anything trendy like that, but it’s fast as hell, easy to code to, builds with cmake easily, actively developed, and runs one of the biggest sites on the Web.
I have yet to find a major downside.
header-only slows compilation down just so you can avoid adding in a single line in your build chain of choice. It's just not a trade off worth making imo.
So to me, not being header only is a pro, not a con.
Which is something not even Python accomplished in half that time.