Even with modern C++ it’s loaded with seg fault and undefined behavior footguns.
The times when C++ feels more ergonomic than Rust are the times when you’re writing unsafe code and there’s undefined behavior lurking in there, waiting to ambush you once you’ve sent it to production. Code that is 100% guaranteed safe is always, and I really want to emphasize this: always more ergonomic to write in Rust than it is to write in C++.
Show me any case where C++ code seems more ergonomic than its Rust equivalent, and I will always be able to show you how either the C++ code has a bug hiding in it or how the Rust code can be revised with syntactic sugar to be more ergonomic than the C++.
Having the ability to overload functions or constructors without a million Stuff::with_x variants is something I consider more ergonomic and not unsafe. I know the Rust community prefers explicitness in many places, but explicitness and safety are somewhat orthogonal in language design. I consider e.g. Swift to be a safe and ergonomic/sugared language, that borrows, no pun intended, a lot of ideas from Rust
There are several ways to achieve an effect equivalent to operator overloading in Rust, depending on exactly how you want the overloading to work.
The most common is
fn do_something(arg: impl Into<Args>) {
...
}
This lets you pass in anything into the function that can be converted into the Args type. If you define the Args type yourself then you can also define any conversion that you want, and you can make any construction method you want for it. It’s a small touch more explicit than C++'s operator overloading, but I think it pays off overall because you know exactly what function implementation all different choices of arguments will be funneling into.
I’ll admit there’s one thing from C++ that I frequently wish were available in Rust: specialization. Generics in Rust aren’t exactly the same as templates in C++ but they’re close enough that the concept of specialization could apply to traits and generics. There is ongoing work to bring specialization into the language, but it’s taking a long time, and one of my projects in particular would seriously benefit from them being available.
Still, Rust will have specialization support long before C++ has caught up to even a quarter of the benefits that Rust has over it.
Even with modern C++ it’s loaded with seg fault and undefined behavior footguns.
The times when C++ feels more ergonomic than Rust are the times when you’re writing unsafe code and there’s undefined behavior lurking in there, waiting to ambush you once you’ve sent it to production. Code that is 100% guaranteed safe is always, and I really want to emphasize this: always more ergonomic to write in Rust than it is to write in C++.
Show me any case where C++ code seems more ergonomic than its Rust equivalent, and I will always be able to show you how either the C++ code has a bug hiding in it or how the Rust code can be revised with syntactic sugar to be more ergonomic than the C++.
Having the ability to overload functions or constructors without a million
Stuff::with_x
variants is something I consider more ergonomic and not unsafe. I know the Rust community prefers explicitness in many places, but explicitness and safety are somewhat orthogonal in language design. I consider e.g. Swift to be a safe and ergonomic/sugared language, that borrows, no pun intended, a lot of ideas from RustThere are several ways to achieve an effect equivalent to operator overloading in Rust, depending on exactly how you want the overloading to work.
The most common is
fn do_something(arg: impl Into<Args>) { ... }
This lets you pass in anything into the function that can be converted into the
Args
type. If you define theArgs
type yourself then you can also define any conversion that you want, and you can make any construction method you want for it. It’s a small touch more explicit than C++'s operator overloading, but I think it pays off overall because you know exactly what function implementation all different choices of arguments will be funneling into.I’ll admit there’s one thing from C++ that I frequently wish were available in Rust: specialization. Generics in Rust aren’t exactly the same as templates in C++ but they’re close enough that the concept of specialization could apply to traits and generics. There is ongoing work to bring specialization into the language, but it’s taking a long time, and one of my projects in particular would seriously benefit from them being available.
Still, Rust will have specialization support long before C++ has caught up to even a quarter of the benefits that Rust has over it.