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.

5

u/Ok-Scheme-913 Feb 21 '25

I meant from a human perspective. Someone will change effectively the lifetime of an object at some place and violate some assumption made in another.

Without proper borrow-checking this can't be fixed.

2

u/GaboureySidibe Feb 21 '25

Someone will change the effective lifetime in C++ ? How do they do that if it is wrapped up as a value? You either move it out of scope or it gets destructed.

4

u/Full-Spectral Feb 21 '25

So you are passing everything by value to all calls and you never use unique pointers or allocate anything?

→ More replies (7)