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

Most people stop feeling like they are fighting with rust a few months into using it. The borrow checker is something that becomes second nature and you still use the same techniques that would please the borrow checker outside of rust because it's generally better program structure in many cases and avoids bugs. If you want to do something that you know us correct that rust normally doesn't allow, just use unsafe. It's not the end of the world. You don't need to resort to a different language to achieve that same result.

This isn't to say it's better or worse than zig. If you're developing software and zig works for your needs, go for it. I'd like to see it used on a 100+ person project to see how it might hold up to the problems that I tend to see in c++, which largely arise for people not knowing about constraints that are not tracked explicitly by the compiler. On projects with less people, this doesn't happen as often.



The ergonomics of unsafe rust are abysmal. It would have been 10 times better if they just let you do inline C instead.


Do you have some examples of what's bad about the ergonomics?


https://chadaustin.me/2024/10/intrusive-linked-list-in-rust/

https://news.ycombinator.com/item?id=41944121

The TLDR is that there’s all sorts of invariants that the Rust compiler internals assume about Rust code (eg pointers don’t alias). In C such assumptions can’t be made. Unsafe rust requires you to uphold all the same invariants that safe rust does without any guardrails and it has more such assumptions than C. C however is uniformly dangerous - there isn’t a safe subset to write your code in.

One example would be that you could have something like:

    let x = 5;
    do_something(&x as *const _ as *mut _);
Now do_something might dereference and write to the pointer. Now you have non-local safety to reason about because if the compiler realizes you’ve tried to dereference a mutable pointer to an immutable variable it’s free to declare that UB and do bad unsound things (the non-locality is because the unsafe is inside do_something but the problem is with the pointer cast in safe rust). There’s all sorts of subtle things like that.


> The TLDR is that there’s all sorts of invariants that the Rust compiler internals assume about Rust code (eg pointers don’t alias).

There are fairly straightforward ways to disclaim these invariants to a greater or lesser extent as appropriate, such as accepting &Cell<T> arguments (or even, e.g. Option<&Cell<T>>) in lieu of &mut T. But the Rust standard library is not yet comprehensively built with this in mind, so this might be an area where Zig's library facilities have a real advantage unless an effort is made to address this gap.


Almost everything. Can't even do pointer arithmetic without x.add() and x.offset()


>Most people stop feeling like they are fighting with rust a few months into using it. The borrow checker is something that becomes second nature

People keep saying that, but I've also seen many who've used Rust for years, in big projects, say the opposite: it gets slightly better as you learn to oblige the borrow checker instictively, but it remains always a kind of annoyance and a friction.


Perhaps that's due to only learning how to treat the symptoms rather than the cause. Building intuition requires understanding why the compiler prefers something different. People coming from C++ tend to get this fairly quickly as they understand the problems rust solves for them, but folks coming from higher level languages don't always see it the same way because they may have not had to deal with those problems.




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

Search: