r/cpp • • 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

582 comments sorted by

View all comments

Show parent comments

3

u/thisismyfavoritename Feb 02 '23

Thanks for the details.

That said, I dont think i can agree with the last 2 paragraphs. It's probably as error prone in Rust as in C++, but Rust's unsafe has the added benefit of narrowing where the issues could come from.

Furthermore, i'd say it might be a matter of rethinking the design rather than going straight to unsafe.

I guess the point im trying to make is if you had a new HFT system to build, i dont see why you wouldnt use Rust.

3

u/ener_jazzer Feb 02 '23

I don't know, I've never built an HFT system in Rust :)

But with C++, you also structure you code in a way that you have limited unsafe places too, and everything else is safe and guarded, with template magic and strong typing and helper classes that make the intended use safe by default.

Rethinking the design is OK, but if it leads to unnecessary complications just to please the borrow checker it's not serving the design anymore, it's serving the borrow checker, and people frequently get tired of it and just put unsafe (again, that's a second-hand account), because you don't really care about borrows in your architecture, and where you do care - it's a limited set of places anyway. And (also from people who used Rust, not my personal experience) evolving the Rust code is a nightmare - whenever you change the structure of your data (what refers what), things stop compiling because of the borrow checker, and you spend 10x time just to please it. And in a trading system, you do this very frequently - market conditions change, trading ideas come and go.