Remix.run Logo
▲ uecker a day ago

As if not a lot of Rust marketing was based on blurring exactly the distinction between "completely eliminates all memory safety issue" (Safe Rust) and "competed with C/C++ as a system programming language" (Rust including its unsafe part).

▲preg_match a day ago | parent [-]

Even comparing to C++ it’s a huge improvement, because all of C++ is unsafe. Unsafe rust, even in codebases that utilize it, is a small minority of the code.

▲uecker a day ago | parent [-]

This "all C++ is unsafe" is similarly exaggerated Rust marketing claim. It is logically equivalent to "all Rust code is unsafe because it may contain unsafe" and nonsense for the same reason. The only claim you can make is that it is easier to screen for the unsafe parts because it is marked more clearly. I would agree with this much more limited statement.

▲tialaramex a day ago | parent | next [-]

> This "all C++ is unsafe" is similarly exaggerated Rust marketing claim

It really isn't, and because I have no doubt you made this assertion genuinely that is itself a problem for their language.

C++ APIs with broad - and thus actually safe - contracts are very rare. Most of the time what we'll find is that there were a few "obvious" assumptions narrowing a seemingly wide contract, an iterator that's assumed to be non-null, a parameter that's expected to be in bounds, or to have this or that desirable property - and if it doesn't while Rust would reject the program alas in C++ it's just Undefined Behaviour so too bad you lose.

The quintessential example is sorting. Maybe we've got a billion Doodads and we sort them. What happens if our sort order is incoherent nonsense, either because our type doesn't actually have a total order or because we provided an explicit ordering rule which was not coherent? In Rust the answer is that this remains safe, since there was no coherent order we can't really say that the Doodads are now "sorted", but the same billion Doodads are there. In C++ that's Undefined Behaviour. Anything could happen. In the real world maybe some of the C++ Doodads are corrupted, or duplicated, or the total number of Doodads changes, maybe arbitrary code is executed, it's a horror show.

▲IshKebab a day ago | parent | prev [-]

The fact is that in practice Rust essentially eliminates all memory safety issues. You can describe that however you want, but most people are perfectly happy with "Rust is memory safe", and you know what they mean when they say it.

▲uecker a day ago | parent [-]

In practice Rust does not eliminate all memory safety issues. So it depends what you mean by "essentially". And then the question is what you compare it to. It is certainly much better than average C++ code.

▲IshKebab a day ago | parent [-]

It absolutely does.

> Our historical data for C and C++ shows a density of closer to 1,000 memory safety vulnerabilities per MLOC. Our Rust code is currently tracking at a density orders of magnitude lower: a more than 1000x reduction.

https://blog.google/security/rust-in-android-move-fast-fix-t...

I await your tediously predictable "1000x reduction isn't eliminated" response.

▲uecker 17 hours ago | parent [-]

I think this data is confounded in many ways, even assuming I would trust a blog post. But I also do not really doubt that there is advantage of average Rust code over average C++ code. There are C projects (and I suspect also C++ projects) with a very good track record in terms of memory safety, and they do it somehow magically without Rust. I think that would be a more interesting comparison to study. But ultimately, I also do not think this even a terrible important or interesting questing. It may be much more important to a company that tries to put unhackable advertisement and spyware platform into everybody's pockets. For my own security the fact that I get limited security support for Rust packages is far more concerning than memory safety ever was.

▲IshKebab 16 hours ago | parent [-]

> There are C projects (and I suspect also C++ projects) with a very good track record in terms of memory safety

Such as? I have never heard of any that had even vaguely good memory safety track records, unless they either a) never free memory (this is how Ada solves the problem), or b) aren't programs where memory safety is a significant factor, so nobody is looking (e.g. single player games, compilers, shells).

▲uecker 8 hours ago | parent [-]

Never freeing memory is a strategy that is used in the embedded world a lot. There are also a lot industrial applications where code is formally verified. (eBPF is an example where C code is verified to be safe in an open source context).

If you look in the open source world for larger projects which just use regular old-style C. I think OpenBSD and curl have a very good track record, probably also the projects by DJB (but I did not follow recent history). I am sure I can find many more examples.