| ▲ | slaymaker1907 3 hours ago | |
I have a huge disagreement here. You should absolutely be using Arc and Rc for any references *that live outside of the call stack.* Don't do weird crap with lifetimes to try and convince the compiler that what you're doing is ok, just throw Rc/Arc on it and be done with it. The Rc/Arc advice also applies to C++ IMO, though you use different constructs, std::shared obviously, but there is a strong argument to be made for a std::shared_st or something which is single threaded. It would not surprise me if this advice comes from experience with C++ where there is no Rc so reference counting is very expensive. Even so, you can greatly reduce the expense by passing things by ref where lifetimes are simple which is the vast majority of the time. | ||
| ▲ | i2talics 3 hours ago | parent | next [-] | |
I think using refcounting can allow you to get lazy with your object graphs, throwing referencing to objects around everywhere and then losing the ability to conceptualize who owns what and who is responsible for who (so to speak). Sticking to a stricter ownership graph forces you to be more deliberate with how your types are designed and this can lead to better architecture in the long run. | ||
| ▲ | wtetzner 2 hours ago | parent | prev [-] | |
I find using lifetimes to be simpler and easier to follow than reference counting, unless you're in a situation where you actually need a shared lifetime. Adding Rc/Arc is just another layer of indirection and noise that makes the code hard to read. | ||