3 ms·
Good question. Thinking about it, I would choose '@'. So only when I read something like: fn print_one<'a>(x: &'a i32) using @ fn print_one<@a>(x: &@a i32) I ca
by tcmart14 4y ago
Good question. Thinking about it, I would choose '@'. So only when I read something like:
fn print_one<'a>(x: &'a i32)
using @
fn print_one<@a>(x: &@a i32)
I can would see it as I sort of semantically read it. Function print_one AT lifetime of a.
- JoshTriplett 4y agoFair enough. I agree that that would have been more evocative of meaning. On the other hand, I also think that this: &'a X looks less like Perl / line noise than this: &@a X . In any case, not something we'd be likely to change at this point, but I agree that ' is effectively "arbitrary unique symbol with no evocative meaning". (Arguably the same is true for things like & for "address of", but that has a long history in many languages which makes it more intuitive for current developers.)
- Thiez 4y agoI think way way back (about 10 years ago) the syntax was &x\a The current tick is much easier on the eyes.
- tialaramex 4y agoOne thing I wonder about, although I don't have a clear recommendation, is the preponderance of single character lifetimes. Other than 'static, a Rust beginner is unlikely to run into any lifetime with a meaningful name for quite a while. If when learning a new language you only ever saw variables named a, x, t, s, v and m it's not a big jump to guess that p, z and b would be allowed as well, but would you assume that in fact the language allows big_set and old_corp_logo as identifiers and it just forgot to mention that ? I'm not sure I would. The Rust standard library does have lifetimes with reasonable names, for example std::thread::Scope needs two lifetimes and it names them 'scope and 'env which, although brief, are clearly not single letters. But most of the library and documentation doesn't bother with meaningful names, since it doesn't have anything worth saying about the lifetime, e.g. the signature of str::ends_with: pub fn ends_with<'a, P>(&'a self, pat: P) -> bool where P: Pattern<'a>, <P as Pattern<'a>>::Searcher: ReverseSearcher<'a>
- JoshTriplett 4y agoThis is absolutely true, and I completely agree. When I'm writing code related to git, I have lots of 'repo and 'tree lifetimes, and I think that's much more readable than 'a and 'b. I think it'd be a really good idea for the standard library to change many of its lifetimes to be descriptive, to encourage others to do the same. With my libs-api team hat on, I'd happily merge PRs that do that. (In small batches, please, not the whole library at once.)