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

chore: replace usage of new() with default() #875

Merged
merged 9 commits into from
Feb 24, 2023

Conversation

Ethan-000
Copy link
Contributor

@Ethan-000 Ethan-000 commented Feb 19, 2023

Related issue(s)

Related to #874

Description

See Constructors section of the guide in the issue

Summary of changes

  1. Add impl Default to new() functions that do not take inputs.
  2. Change new() to call the default function. (update: remove empty new())
    // 3. vec![] to Vec::new() (discarded this change)

// I'm not sure if removing new() functions is a good idea (this seems to be what the guide is suggesting from my //understanding) so I changed them to calling the default function.

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.
  • This PR requires documentation updates when merged.

Additional context

@Ethan-000 Ethan-000 changed the title chore: new() to default chore: new() to default and vec![] to Vec::new() Feb 19, 2023
Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

I'm unsure of this refactoring - I don't think it improves readability by much and don't think we should strictly follow a style guide even for small items.

In regards to having both T::new and T::default, my preference would be to only having T::default (if it can be automatically derived, or it is required for a T: Default bound), or T::new otherwise. No need to have 2 functions that do the same thing.

@guipublic
Copy link
Contributor

If new does not do anything special, I am OK to replace it with default, it enables other types to automatically derive if they use one with default. I also agree that in that case we can keep only default and not have both.

@Ethan-000 Ethan-000 changed the title chore: new() to default and vec![] to Vec::new() chore: new() to default Feb 22, 2023
@Ethan-000 Ethan-000 requested review from jfecher and removed request for kevaundray and guipublic February 22, 2023 13:27
@Ethan-000
Copy link
Contributor Author

didn't mean to remove review request @guipublic @kevaundray

@Ethan-000 Ethan-000 requested a review from jfecher February 22, 2023 21:49
jfecher
jfecher previously approved these changes Feb 23, 2023
kevaundray
kevaundray previously approved these changes Feb 24, 2023
@kevaundray kevaundray enabled auto-merge February 24, 2023 11:09
auto-merge was automatically disabled February 24, 2023 11:32

Head branch was pushed to by a user without write access

@TomAFrench TomAFrench added this pull request to the merge queue Feb 24, 2023
@TomAFrench TomAFrench changed the title chore: new() to default chore: replace usage of new() with default() Feb 24, 2023
Merged via the queue into noir-lang:master with commit 440f778 Feb 24, 2023
@Ethan-000 Ethan-000 deleted the new-to-default branch February 24, 2023 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants