4 ms·
From my limited experience, passing variables around between threads is quite painful in Rust, async makes sense therefore as it allows you to reduce shared own
by ThePhysicist 4y ago
From my limited experience, passing variables around between threads is quite painful in Rust, async makes sense therefore as it allows you to reduce shared ownership of variables. A while ago I wrote a simple multi-threaded networking library in Rust and things that would be trivial in C/C++, like accepting a network connection and passing the socket handle to a thread with some extra information were really tricky (maybe just because I was inexperienced in Rust) and took some quite ugly code to solve. In the end the program I produced had significant performance bottlenecks and was quite hard to understand.
I rewrote the same thing in Golang afterwards, took me maybe 10 % of the time and the code I produced was very readable and extremely fast. After that I'm a little burnt regarding Rust and have a hard time buying all the hype around it. I guess it has potential for embedded systems and other memory-constrained environments though, as Golang can't compete there right now due to the large size of the runtime, though there are projects like Tinygo that might eventually fill that gap as well. So I'm probably more hyped about Zig than Rust for now when it comes to next-gen languages.
- sk0g 4y agoI'm working my way through the Rust book right now, and that's sort of the sense I'm getting too. The compiler is quite good at catching some issues relating to memory access predominantly. There's many ways to solve multi-threading issues (&, &mut, Rc, Box, Arc, ...). If you do it the right way the compiler won't get in your way much, but if you do it the wrong way it will be a cat and mouse game where you do your best to confuse the compiler into believing your code is fine-ish.
- naasking 4y ago> (maybe just because I was inexperienced in Rust) Given the one consistent thing I hear about Rust is it's steep learning curve, I'd almost certainly chalk it up to that. Go let's you ignore details that you can't ignore in Rust, and being forced to think about and organize data in a certain way to eliminate that pain is a skill that no doubt takes practice.
- guitarbill 4y agoIn my experience, many things that are trivial in C/C++ are unfortunately subtly wrong, especially involving threads. It's a shame that your C or C++ experience doesn't translate to Rust. For me a lot of things just clicked in Rust. Although there certainly was the occasional "why can't I just do this?" that took much longer to reason all the way through. It's maybe something Rust tutorials need to be better at, or maybe there ought to be tutorials specifically for e.g. C++ folks? For better or worse, Rust gives you the choice (& vs Arc, etc), and it's yours to make. These choices are fatiguing to make if you aren't used to them (I believe C/C++ is similar for newcomers). In the long run, making those choices explicit is where Rust really shines in codebases IMO. Nothing wrong with using Golang if it works for you. I sometimes wish for a middle ground between Python and Rust, but Golang isn't for me.