-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Prefer App::default() over App::new() in doc, examples, test #20451
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
base: main
Are you sure you want to change the base?
Conversation
- We are currently following a convention that I see repeatedly across the crates.io ecosystem. We provide a wrapper App::new() as a proxy for App::default() This comes from a RUST convention that default is the preferred constructor (when no additional parameters are required). As a matter of library design we provide App::new only for the flexibility of permitting the game engine developer's whim. This PR takes the line that when documenting the codebase, when showcasing examples or when testing the codebase we should used the preferred constructor as a way of nudging the reader down that path. ## Solution - Global Replace of App::new() for App::default() - Visual inspection of PR to ensure only pertinent changes are made. ## Testing - Lots of tests have been updated, no change in functionality
This may be an unrelated issue as locally - this passes, and fails on the github cargo run -p ci -- lints Hmm I will ask on discord. |
here is my observation
running this locally on this PR was passing I noticed the CI tool using pull in the latest rustc ( dated today 7Aug ) so I ran
and now all the test a failing locally, with the same problems as identified by CI To confirm this I checkout out main .. ran the docs and saw the new error without this patch applied. So the CI testing pipeline is broken at the moment. |
I'm going to ask for a citation on this. Where are these convention/guidelines coming from? Though it seldom matters in this particular case, |
This isn't really a widely agreed-upon convention to my knowledge. Every single data structure in the standard library provides a |
Clippy will warn you if you create a constructor with no parameters without a default implementation, which would indicate that having both
|
The best reference I could find from this website https://rust-unofficial.github.io/patterns/intro.html Which I think is good for API design in general Speaking neutraly I should emphasis "unofficial" as it is easy to misread.... Here is the outline of the convention that is already encoded into bevy
|
Is there a git repo that you are thinking of ,,,, I am not sure. I have a mind to file more PRs |
Implementing both |
I completely disagree with this change. Default has not the same semantic meaning as new, and shouldn't be... the default. It's recommended by rust to implement it when possible because it makes it easier to work with autoderivation, but it's not a recommendation to use it everywhere. |
Objective
We are currently following a convention that I see repeatedly across the crates.io ecosystem.
We provide a wrapper App::new() as a proxy for App::default()
This comes from a RUST convention that default is the preferred constructor (when no additional parameters are required).
As a matter of library design we provide App::new only for the flexibility of permitting the game engine developer's whim.
This PR takes the line that when documenting the codebase, when showcasing examples or when testing the codebase we should used the preferred constructor as a way of nudging the reader down that path.
Solution
Testing