3 ms·
> But it irks me when rust blogs misrepresent C to show that Rust is better I don't believe my article explicitly states that Rust is better. It marvels often
by fasterthanlime 7y ago
> But it irks me when rust blogs misrepresent C to show that Rust is better
I don't believe my article explicitly states that Rust is better. It marvels often at what is possible and what isn't in both languages, and then leaves the reader to draw their own conclusions.
I am being cavalier with the C code on purpose, because /this is how a lot of real world code is written/.
Have you taken a look at the CVE search linked in the article? Those aren't just mistakes you find in hobby projects. Search for "ICU", "Chromium", or "ffmpeg" for entertaining morning reads.
These problems keep happening because C prevents developers from modeling problems correctly, and does not prevent many error classes /which we know now can be checked for at compile-time/.
> Also you can have const memory in C that will crash if you cast it to non-const and write to it. You can call out to the OS to mark a chunk of memory it as read only
Well... you can use mprotect (or equivalent) to change the protection of one or more memory pages, not any chunk you want.
And it has no relation to const whatsoever. const still remains an opt-in annotation, too easily sidestepped (on purpose or otherwise).
> The reason it's not as built into C as it is for Rust is that C was in part designed for and currently runs on hardware where there isn't read-only-memory outside of a physical ROM chip
I'm not sure I follow. Rust certainly doesn't change page protection to enforce immutability. It's all compile-time checks, just much stricter and more accurate ones (because of the borrow rules, lifetime information etc.)
Everything about those checks disappears at runtime though, so it's definitely not a feature that gets in the way of Rust embedded.
> Something about this sentence screams Rust programmer but I can't put my finger on why
I can assure your there's a fair amount of Rust developers who also take themselves entirely too seriously, so it's not really a unique trait.
In all seriousness, I'd recommend that you keep learning about Rust, if only so you can dislike it based on more accurate information. And if you read so much you end up liking it, well, those things happen.
(For alternative responses to a similar line or skepticism, see this thread: https://lobste.rs/s/d8llrf/working_with_strings_rust#c_pkdugk https://lobste.rs/s/d8llrf/working_with_strings_rust#c_pkdug... )