Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use concrete names for concrete lifetimes in ch10-03 #3061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Noratrieb
Copy link
Member

At the start of chapter 10-03, the concept of a "lifetime" is introduced, by talking about the concrete lifetimes of values. These lifetimes are referred to using 'a and 'b. This can be confusing, since these names are usually used for generic lifetimes. The difference between generic lifetimes and concrete lifetimes may not be obvious, so don't make it less obvious by using generic names for the concrete lifetimes.

The names are up to debate, I've chosen 'outer_scope and 'inner_scope for the nested scope example, and 'full_scope and 'partial_scope for the example where both are in the same scope.

At the start of chapter 10-03, the concept of a "lifetime" is introduced, by talking about the concrete lifetimes of values. These lifetimes are referred to using `'a` and `'b`. This can be confusing, since these names are usually used for generic lifetimes. The difference between generic lifetimes and concrete lifetimes may not be obvious, so don't make it less obvious by using generic names for the concrete lifetimes.
@carols10cents carols10cents added this to the ch10 milestone Feb 21, 2022
@carols10cents
Copy link
Member

I'm not sure this change makes it better. There's nothing stopping anyone from naming their generic lifetimes something like 'inner_scope; longer, more descriptive names for lifetime parameters isn't common but it does happen (and personally, I rather like more descriptive names).

What if there wasn't a ' at all? Or underscores? So that the diagrams were just labeled "inner scope" and "outer scope"? Would that make these diagrams clearer or less clear for you?

@Noratrieb
Copy link
Member Author

The point of this change was, that 'a is what's used for a generic lifetime in the book, so not using the generic lifetime name for a concrete lifetime here might help to disambiguate the two. It's been a year since I learned Rust and a can't remember it exactly, but I think lifetime annotations like this were one of the more difficult things to learn, and I was confused by what fn foo<'a> exactly means.

I'm unsure on whether removing ' makes it better. On one hand, it makes the difference between a generic lifetime parameter and an actual lifetime even clearer, but maybe it's too much?

But I think removing it is worth a try.

Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mulling (by no means committed!) – another option here is to use '0 and '1, and explain that these match the way Rust will sometimes name the anonymous lifetimes it tracks. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants