Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You are confusing best practice for what is done all too often. Unsafe should be small blocks, but I've seen people put unsafe on everything even though it isn't needed thus making it hard to find where it is needed. I'm not a rust programmer, but I'm lead to believe that those people then do things that need unsafe - but a safe option not only exists but would have been easier to write.


For very low-level stuff (e.g. embedded) you might need a lot of unsafe. For the vast majority of software it’s extremely rare. I worked full time for five years on a Rust project (https://github.com/MaterializeInc/materialize) and anecdotally, unsafe code was much less than 1% of the codebase.


I don't have direct experience, but from what I can gather between others, and my general embedded experience, unsafe in the worse case of embedded would still be just a small percentage of all code. (a device driver which would need unsafe to deal with hardware still has a lot of code that doesn't deal with hardware)

There is some rust code out there that is more than 50% unsafe though.


I'm also not a Rust programmer so I can't comment on whether people are overusing it, I was commenting on the suggestion that "if you're using unsafe{} in Rust what's the point in using Rust at all?" implying that it's basically C at that point, and it isn't - there's still a lot of safety checks the compiler does even in unsafe mode.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: