3 ms·
I don't think it is. I ran into the same pitfall. Instead of taking String and passing around &str, I did .clone() everywhere. Kind of gross? The better advice
by MuffinFlavored 4y ago
I don't think it is. I ran into the same pitfall. Instead of taking String and passing around &str, I did .clone() everywhere. Kind of gross? The better advice I think is "lean on passing around borrowed parameters as much as possible, otherwise you're going to run into Copy+Clone hell. I would be curious to learn from somebody "even better" at Rust if that is bad advice.
That and, I just wrap everything "hard" in some combination of lazy_static / Arc+Mutex.
- echelon 4y agoGreat way to learn your bearings. Then once you get the lay of the land you recognize that's not the way to do things. It'd be neat if the language had a "beginner mode" flag where the compiler could recommend simple things like abuse of the heap. All you need is a day or two with it, then you can take off the training wheels. Write one to throw away. Learning is messy and hands-on, not rote and academic.
- iudqnolq 4y agoI would put it as "when it isn't too tricky to do so write your program such that data flows one way". When data flows downwards it's often simple to have the top layer own and then pass down references. But if you start running into lots of issues doing that it's probably a fundamental issue with your architecture. So you need to either rethink it or give up and try a different kind of approach. Both are valid, but I think people who try to muddle through without either dramatic option are the ones who end up very frustrated with Rust.
- PeterWhittaker 4y agoI split my time between our hardware products (C and Rust) and our software product (JS everywhere, node in the back, React in the front). Reading your comment I had two simultaneous thoughts.... 1. <squinting appreciatively> Clever, cool way to think of it... ...and if you need information back at the top level, send it back via a Result.... 2. <brows raised in horror, shuddering in React> State management hell! :->