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

lib: Add contribution guidelines #272083

Merged
merged 1 commit into from
Dec 19, 2023
Merged

lib: Add contribution guidelines #272083

merged 1 commit into from
Dec 19, 2023

Conversation

infinisil
Copy link
Member

Description of changes

This should be written down so we can refer to it.

This work is sponsored by Antithesis


Add a 👍 reaction to pull requests you find important.

@infinisil infinisil requested a review from roberth December 4, 2023 16:52
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Dec 4, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Dec 4, 2023
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Unfortunately we can't automate ourselves away, but better expectations and structure are great goals.

I just hope people will find it. Maybe link it from relevant other contributing oriented pages? I'm thinking the general coding guidelines, and maybe the PR template?

lib/README.md Outdated
## Contributing

Follow these guidelines for proposing a change to the interface of `lib`:
- Motivation: Clearly describe why the change is necessary and its use cases
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Motivation: Clearly describe why the change is necessary and its use cases
- Provide a motivation: Clearly describe why the change is necessary and its use cases

Copy link
Member

Choose a reason for hiding this comment

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

If your suggestion is to use imperative titles, I believe this is better:

- Do that thing
   
  <More details about why doing that things is good>

lib/README.md Outdated
If the same can be done with the existing interface,
consider just updating the documentation with more examples and links.
This is also known as the [Fairbairn Threshold](https://wiki.haskell.org/Fairbairn_threshold).
- Single PR: Don't have multiple changes in one PR, instead split it up
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Single PR: Don't have multiple changes in one PR, instead split it up
- Single purpose PR: Don't have multiple changes in one PR, instead split it up. It keeps the conversation focused and has a higher chance of getting merged.

lib/README.md Outdated
- If there's no obvious best name, include the alternatives you considered
- Documentation: Update the reference documentation to reflect the change
- Add links to related functions
- Tests: Add reasonable test coverage for the change
Copy link
Member

Choose a reason for hiding this comment

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

What do we consider reasonable? Can we provide a rule of thumb?
Some recommendations I would suggest:

Suggested change
- Tests: Add reasonable test coverage for the change
- Tests: Add good test coverage for the change
- For each parameter, test edge cases of the types such as empty values.
- Look for tricky inputs, to a reasonable degree. For example: a string with a string context (e.g. adding some file to the store), or a path value that points to a non-existing path if that should be accepted.
- Make sure to cover all code paths, except perhaps assertions that relate to internal invariants, as those may be impossible to trigger.
- We don't require checks on error messages for files tested by test suites that don't support this. For new error messages in the module system, we do.

@infinisil infinisil force-pushed the lib-contrib branch 4 times, most recently from a421656 to 5925f69 Compare December 4, 2023 23:12
@infinisil
Copy link
Member Author

@roberth I incorporated your feedback, though I did a bit of rewriting for a more consistent style (diff)

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Love the new layout.
Should the items be headers though? That way we get to link to them too.


Name variables well, even if they're internal.
Add code comments where the code isn't self-explanatory.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
As a baseline, follow the [Nixpkgs code conventions](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#code-conventions).

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a fan of that section, but sure we have it, let's reference it. Most of it should become obsolete with NixOS/rfcs#166 :)

@infinisil
Copy link
Member Author

infinisil commented Dec 5, 2023

Should the items be headers though? That way we get to link to them too.

I did try that out briefly but decided against it because I don't want people to just link to one part of it. This section should be short enough that people can read the entire one without focusing on just one aspect.

I applied all your suggestions 🙂 (diff)

@roberth
Copy link
Member

roberth commented Dec 5, 2023

I don't want people to just link to one part of it.

Why's that?

This section should be short

I agree, but seems quite unrelated.

@infinisil
Copy link
Member Author

I don't want people to just link to one part of it.

Why's that?

Hmm I didn't think it's needed, but I guess I don't mind very much, I'll change that.

@roberth
Copy link
Member

roberth commented Dec 7, 2023

Actually would be good to have links. I mentioned it in the review summary/preface thingy, which is too easy to overlook. Bad UI.

Maybe link it from relevant other contributing oriented pages? I'm thinking the general coding guidelines, and maybe the PR template?

@infinisil
Copy link
Member Author

Oh yeah, sorry I was a bit sloppy with properly addressing the feedback this time.

I just hope people will find it. Maybe link it from relevant other contributing oriented pages? I'm thinking the general coding guidelines, and maybe the PR template?

I am fairly happy with the overview section in CONTRIBUTING.md, which links to lib/README.md


This keeps the conversation focused and has a higher chance of getting merged.

### Name the interface appropriately
Copy link
Member

Choose a reason for hiding this comment

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

This section feels a bit arbitrary. I agree that naming is important, but I'm having a hard time to figure out if a name is good or bad, only based on this information.

Providing examples of good and bad names accompanied with explanations, or links to similar functional libraries (maybe hoogle or elm?) might be a good addition. Or maybe recommend people to read through earlier PRs tagged with https://github.com/NixOS/nixpkgs/labels/6.topic:%20lib, to see the name discussions there and get a feeling for it?

Copy link
Member

Choose a reason for hiding this comment

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

If we're going to refer to languages, we'd have to point out the differences as well. That is, link to a document that does that.
Here's a few things:

  • Nix lists don't have lazy spines like in Haskell, nor is cons cheap.
  • Maybe and Nullable are very different. mapNullable is not a lawful functor. It behaves like >>= / flatMap. Nullable (Nullable a) == Nullable a, etc. Less suitable for composition.
  • Haskell Map.union is flipped compared to //.

Copy link
Member

Choose a reason for hiding this comment

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

Until we codify anything: maybe make it "here's what we think" and "if you don't know, just open a PR and let's talk about it"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added

If you don't know what name to choose, indicate this as a discussion point in the PR.

to this item. I don't think we could have very concrete guidelines here for now.

lib/README.md Outdated

Names should be self-explanatory and consistent with the rest of `lib`.
If there's no obvious best name, include the alternatives you considered.
If you don't know what name to choose, indicate this as a discussion point in the PR.
Copy link
Member

Choose a reason for hiding this comment

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

"indicate as discussion point" sounds really heavy.

This sentence also conflicts a bit with the preceding one. Do we really think contributors can't come up with any name whatsoever? It actually seems condescending.

Suggested change
If you don't know what name to choose, indicate this as a discussion point in the PR.

or

Suggested change
If you don't know what name to choose, indicate this as a discussion point in the PR.
If you don't know what name to choose, feel free to say so in the PR description.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really mind either way, ping @h7x4

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

@h7x4 I was hoping to get some thoughts 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright I'll just remove this sentence again. Let's merge before this stalls out for too long. Feel free to open follow-up PRs if there's something to improve.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, the ping went by without me noticing. The thumbs up was intended for the entirety of roberth's comment, so if you removed the sentence I think all is good!

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool thanks!

@infinisil infinisil merged commit 0f8d175 into NixOS:master Dec 19, 2023
@infinisil infinisil deleted the lib-contrib branch December 19, 2023 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants