13 ms·
Imo lifetimes aren't that complex. They're just a wholly new programming language feature - learning lifetimes is hard because you're simultaneously learning th
by p1necone 6y ago
Imo lifetimes aren't that complex. They're just a wholly new programming language feature - learning lifetimes is hard because you're simultaneously learning the syntax and the concept.
Compare to something like generics where it's roughly the same idea in most languages that feature them, you just need to learn the syntax and maybe some edge details that differ between languages (Contravariance and Covariance say hello!).
If you've ever helped someone who's entirely new to programming learn their first language you might see some parallels with experienced programmers learning entirely new features like lifetimes.
- EamonnMR 6y agoI don't think the problem with lifetimes is that they are complex, it's that other languages handle lifetimes for you, but Rust outs to onus on you to manage them. C++ also has complex object lifetimes but if you don't invoke that complexity you don't need to deal with it.
- theon144 6y ago>C++ also has complex object lifetimes but if you don't invoke that complexity you don't need to deal with it. I would tend to disagree? In C++, I regularly ran into issues where I "invoked" the complexity with memory/object management completely incidentally, and as the saying goes, shot myself in the foot (or rather, both feet, because lifetime management issues often result in heisenbugs and other really nasty phenomena). Rust makes that complexity explicit, which is really an analogous argument as with static/dynamic typing; it's not that the dynamic languages "handle typing for you", and "static" simply requires more work. Rather, you're forced to deal with it at the very start, instead of down the road. Then again I'm rather new to Rust, so I might misunderstand you?
- EamonnMR 6y agoYou're quite right, but it's worth being mindful that for many projects, down the road never comes. It's a very expensive insurance policy.
- Ygg2 6y agoThe only way to handle lifetimes is: A) Introduce burden on programmer B) Introduce burden on runtime (GC basically) You just get to pick your poison. Do you want the upfront cost in syntax (Rust) or do you want the down the line cost (C/C++).