r/programming • • Feb 20 '25

Google's Shift to Rust Programming Cuts Android Memory Vulnerabilities by 68%

https://thehackernews.com/2024/09/googles-shift-to-rust-programming-cuts.html
3.4k Upvotes

475 comments sorted by

View all comments

Show parent comments

3

u/GaboureySidibe Feb 21 '25

I write a lot of modern C++ and I don't have the problems that rust solves because I already can solve them with C++. Using templates and value semantics with no raw pointers (and no raw smart pointers) takes care of destruction and ownership.

Doing curated iteration and not deleting elements from a data structure or modifying keys solves a lot of the other problems. If you need bounds checking on std::vector access (because you are using computed indices rather than iterated indices), use .at().

These things basically take care of the memory problems that rust solves, then you can still use C++ with all its tools, libraries and ecosystem.

21

u/Ok-Scheme-913 Feb 21 '25

It doesn't scale, though.

I can write safe assembly as well, given I'm working alone on it and never doing anything wild. But we are past that for a good reason.

Nonetheless, using existing libraries is definitely a valid reason to keep using C++, though I do think that writing new code in rust (as the article is about) on top of existing codebase is a better choice.

1

u/GaboureySidibe Feb 21 '25 edited Feb 21 '25

It doesn't scale, though.

Says who? Values go out of scope and get destructed. Data structures are iterated. The program looks the same but you don't have to wonder if bounds checking is being secretly elided or not.

If by scale you meant harder to enforce technically across a team then I think you would have a point. I don't know how to use tools to weed out violating these techniques.

13

u/Full-Spectral Feb 21 '25

You are making the standard "just don't make mistakes" argument. And of course this is all about team based development, mostly commercial but also open source, where no amount of communications is sufficient to avoid issues over time. For someone doing a personal project, who can take all the time in the world, it's obviously less of an issue.

But still, even if you are doing a person project, you don't have to take so much time watching your own back if you just use a safe language. As someone who has written large C++ code bases for 35+ years and now is using Rust for my own personal stuff, the difference is enormous.

The argument shouldn't even be about, but wait, I can make C++ safe with a lot of effort. Tt should be why am I wasting my time doing something over and over that a compiler can do without fail every time I compile?

→ More replies (5)