4 ms·
For me, its the lifetime syntax I don't like the most. It doesn't feel "ergonomic" to type something like <`a>. Its mostly the ` I wish were different.
by tcmart14 4y ago
For me, its the lifetime syntax I don't like the most. It doesn't feel "ergonomic" to type something like <`a>. Its mostly the ` I wish were different.
- JoshTriplett 4y ago(Aside: it's 'a , not `a.) One of the hopes is that it's usually not necessary to write those lifetimes explicitly in most programs, unless you're doing something unusual. If you could go back and change it, what would you have used for the lifetime syntax?
- tcmart14 4y agoGood 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.)
- bobbylarrybobby 4y agoDon't you need them anytime you have a struct with borrowed members? Even it just has a Cow you need the lifetime in the struct definition. Sometimes, but not always, you can elide the lifetimes in a function (iirc they have to occur at the outermost layer). But I definitely wouldn't call it unusual.
- dannymi 4y agoYou mean having one ' ? It's the same syntax in Lisp, Haskell, Ocaml, Ada and VHDL.