Remix.run Logo
▲ cogman10 6 hours ago

Probably, particularly in terms of writing correct code.

But C++ allows me to really easily write multithreaded code which I can convince myself is safe :) (and most of the time, is correct, just not on the edge cases). Rust makes that painful.

▲tcfhgj 6 hours ago | parent [-]

> Probably, particularly in terms of writing correct code.

package management, build system, compiler errors, language simplicity (yes, it adds life times, but removes so many other things), Rust macros, language ergonomics (e.g. match, macros, enums, async, if let, etc.), not having to think about certain things going wrong (including not debugging why things went wrong)

> Rust makes [multithreaded code] painful.

Andreas Kling is switching away from C++ to Rust in Ladybird, because of exactly the reversed experience.

I have been using asynchronous multithreading via tokio - something I never dared to in C++. Alone from the compiler errors I have got doing that, I would assume that I would have been dealing with an unbearable amount of debugging of subtle memory issues.

▲cogman10 4 hours ago | parent [-]

> Alone from the compiler errors I have got doing that, I would assume that I would have been dealing with an unbearable amount of debugging of subtle memory issues.

Well, that's the thing about rust and async. It's far more restrictive (necessarily) than the bounds of safety. The hard problem rust runs into is that async functions can be executed outside of lexical and the lifetime tracking of the rust language. To be absolutely safe, rust ends up needing to assume that async can be executed with no respect to the surrounding lifetimes.

Rust would really benefit from something like structured concurrency in terms of the lifetimes of async functions.

▲tcfhgj 2 hours ago | parent [-]

> Well, that's the thing about rust and async. It's far more restrictive (necessarily) than the bounds of safety.

I obviously was not talking about things illegal in safe Rust, which are actually safe, e.g. you cannot send types which are not allowed to be moved across threads across threads in C++ either.

> To be absolutely safe, rust ends up needing to assume that async can be executed with no respect to the surrounding lifetimes.

seems to work with surrounding life times?

https://play.rust-lang.org/?version=stable&mode=debug&editio...