3 ms·
A function returning a value that depends on the lifetime of the function's parameter is not crazy at all. Every class getter method that returns a reference to
by roca 4y ago
A function returning a value that depends on the lifetime of the function's parameter is not crazy at all. Every class getter method that returns a reference to a member of the class does this.
- benreesman 4y agoSure. But returning the address of a stack-allocated object is (usually) broken. There isn't a right and wrong here: sometimes you want to opt in to the check for that, sometimes you want to opt out of it. Sometimes I actually do want to fuck with addresses on the stack in weird, potentially architecture-dependent ways, it's rare but it happens. I happen to think that Rust's linear/affine typing is by far the most usable low/zero-cost memory management model that anyone has demonstrated at scale and a real achievement in practical computer science, but it comes at a pretty serious cost in `Box`-this and `Arc`-that and `Rc`-other-thing and generally the borrow-checker being a PITA about some stuff we're used to doing. Rust is very cool and I use it, but the "using C/C++ is fucking strangers without protection"-vibe got old years ago.
- tialaramex 4y ago> returning the address of a stack-allocated object is (usually) broken. What matters is the lifetime, where the object lives is a rule of thumb for guessing lifetime that results from C++ trauma.
- ncmncm 4y agoHint: getters are code smell. Getters that return references are code stink.