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

Effectively naming lifetimes to help improve code clarity #259

Open
simonsan opened this issue May 21, 2021 · 5 comments
Open

Effectively naming lifetimes to help improve code clarity #259

simonsan opened this issue May 21, 2021 · 5 comments
Labels
A-idiom Area: Idioms C-addition Category: Adding new content, something that didn't exist in the repository before

Comments

@simonsan
Copy link
Collaborator

Interesting and I wonder if that wouldn't be a good addition to this repository?
https://web.archive.org/web/20210521022017/https://www.possiblerust.com/pattern/naming-your-lifetimes

Thoughts?

@simonsan simonsan added C-addition Category: Adding new content, something that didn't exist in the repository before A-idiom Area: Idioms labels May 21, 2021
@pickfire
Copy link
Contributor

This page is available on the web!

@pickfire
Copy link
Contributor

https://www.possiblerust.com/pattern/naming-your-lifetimes

I don't think it is good. It's up to the users and authors how they want to name stuff, some prefer single character some prefer multi characters, but either way both ways works and we should not specifically encourage one or the other, they should think which one is best for the task.

@simonsan
Copy link
Collaborator Author

I don't think it is good. It's up to the users and authors how they want to name stuff, some prefer single character some prefer multi characters, but either way both ways works and we should not specifically encourage one or the other, they should think which one is best for the task.

I think it's like every so often, I agree, that we shouldn't encourage one or another approach but explain what can be achieved by it and how. Giving (dis-)advantages of either approach and talking about the thought process when naming your lifetimes. When you say "they should think which one is best for the task", what if some people have never thought about it before and want to read something about it. Why shouldn't they read something in a rust patterns book about it how others do that? This book should be educational in these ways, also if it's often subjective to the author of the article. But this we can fix over time (the PR review process) and when other people read through it and give feedback.

@pickfire
Copy link
Contributor

pickfire commented May 21, 2021

Just wondering, shouldn't this already be mentioned in the book? Talking about that here is like talking about naming variables, very sensitive. Like c vs counter.

@simonsan
Copy link
Collaborator Author

Just wondering, shouldn't this already be mentioned in the book? Talking about that here is like talking about naming variables, very sensitive. Like c vs counter.

The book talks more about the "what, why and how to use" and they use for their examples lifetimes with the names 'a and 'b. Which is something we could state again, that you can do it like that, but that loses you much clarity in a complex codebase and that sometimes it's better to give them more explicit names and how to chose them accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-idiom Area: Idioms C-addition Category: Adding new content, something that didn't exist in the repository before
Projects
None yet
Development

No branches or pull requests

2 participants