Live data from Hacker News

Comparative unsafety

flak.tedunangst.com

1–10 of 99 posts

Re: Comparative unsafety

#2
> I wrote some rust code.

Actually, he wrote some Rust and some C code wrapped in Rust.

> I was writing an smtp server... the kind of smtp server you'd write in two days.

(sigh)

> The error would have been detected far sooner had I not been lazy and checked the return value of chown (for a file not found error). But [excused here]

You can't, and mustn't avoid C error checking when writing C code, even if it's wrapped in Rust.

I was a TA in a first-semester course in C programming for several years, and one of the harder things to inculcate is how return value checking is not optional. It's very tempting to assume your standard library function just works, always.

Re: Comparative unsafety

#4
> Why am I using my own ffi version of chown instead of the libc crate? The libc crate prototypes chown with unsigned uid_t and gid_t types, and I want to pass -1 because I'm not interested in changing the group. I'll spare you the long rant about how one should never redeclare system interfaces if you can't take the time to do so properly, because it turns out if you dig into it, uid_t boils down to uint32_t, but even so, the manual for chown says -1 should work and I want it to work.

First thing I'd try would be to pass "~0" instead of "-1". Would that work? (Looks like in Rust that would be "!0". I don't know anything about Rust.)

Re: Comparative unsafety

#6
I will concede that it would be nice if I could opt-in to a 'be-really-nitpicky' mode for clippy. I would even do it sometimes. Usually I just want something with a little higher SNR.

Re: Comparative unsafety

#7

> I wrote some rust code. Actually, he wrote some Rust and some C code wrapped in Rust. > I was writing an smtp server... the kind of smtp server you'd write in two days. (sigh) > The error would have been detected far sooner had I not been lazy and checked the return value of chown (for a file not found error). But [excused here] You can't, and mustn't avoid C error checking when writing C code, even if it's wrapped…

>> The error would have been detected far sooner had I not been lazy and checked the return value of chown (for a file not found error). But [excused here]

> You can't, and mustn't [...]

It doesn't really sound like he's trying to excuse anything. Quote the intro more fully:

>>> I used unsafe. It was unsafe. After months of contemplating this unfortunate result, I've found someone else to blame.

Re: Comparative unsafety

#8
From my perspective as someone who knows Rust but primarily works with high-level languages like JavaScript, some developers who from a background of unsafe languages (particularly C and C++) seem incredibly cavalier around `unsafe` blocks in Rust code. It's like they're desensitised to the unsafety.

As someone who is used to working in a language where one absolutely cannot hit memory safety issues or undefined behaviour, you can be damn sure that I'm going to read all the relevant documentation and double/triple the invariants of any unsafe code I write in Rust (and maybe even get it reviewed by someone else).

In some ways unsafe blocks in Rust are more unsafe than the equivalent C or C++ code because you have to uphold Rust's more stringent safety guarantees (e.g. no aliasing of mutable references), but they come with the saving grace that you don't need them very often, so you can afford to really take your time and implement them thoroughly.

Re: Comparative unsafety

#10

This has the most toxic UI I've seen in my life. Switching away from my browser and back again causes the page to re-render, losing my place as it did so. Just awful!

I'm pretty sure it's an artificial loading screen too. There's no way it actually takes that long to render. It's quite an interesting artistic statement.
Post reply on HN