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
doc: add function argument order convention #110060
Conversation
Ordering by usage is the de facto ordering given to arguments. It's logical, and makes finding argument usage easier. Putting lib first is common in NixOS modules, so it's reasonable to mirror this in nixpkgs proper. Additionally, it's not a package as such, has zero dependencies, and can be found used anywhere in a derivation.
I've wondered a bit about this as I write a few packages. I'm a bit pleased to see order-by-usage suggested--because it should be formatter/linter-enforceable. On the other hand, it's also common to interleave comments; I'm less sure if a formatter can just optimistically move the preceding comment, if any, any time it reorders arguments? :) |
Yes. I thought about commenting about semantic groupings, though I waffled since they might actually still group well enough by first use. (Though, no--I hadn't noticed how gnarly ffmpeg is). I guess it might be easier to address with a linter--since it can just complain that the order is wrong and make a human sort out t he comments--as long as it can respect the semantic-grouping concept. I see occasional chatter about docstrings--I hope a principled solution could fit there, if nowhere else. |
ffmpeg is definitely the exception, not the norm. I'm more accustomed to seeing fairly straightforward examples that would likely stand up to this kind of treatment. Presumably you've had a similar experience. What I'd like to see is the whole
|
Also I am saying how it is but I don't think we can enforce this at all or people are getting mad. |
For now, it's a guideline, not a rule. Later, we can have formatting tools apply the reordering for us. I'm not really sure why you'd think people would be mad at having some actual coding conventions, though. The lack of any is a common complaint. |
This is, at its core, a two line change. I've reached my limit with how much bikeshedding I'm willing to deal with at the moment, so I'm leaving it to someone else to carry to the finish line if they want this merged. This kind of feedback is extremely draining to engage with, and seriously demotivates me from contributing. |
It is not just a two line change. This impacts everyone that contributes to nixpkgs and if we do not have the right tooling first then this kind of guideline for enforceable at all. If we have a formatter that does this and most people can agree on using it then we can make the formatter a hard requirement. Right now if I would suggest people to sort their inputs in a PR review I would start a lot of bike sheeting with a lot of people and they would discard my reviews even more. |
That is okay, writing it down is a good start.
Well, you don't need to require it. 100% compliance doesn't have to be the goal until it is supported by tooling. It could be a request on new packages, or a suggestion on fixups. There is room for discretion. @SuperSandro2000, we can't wait for perfect tooling or block improvements in cases where 100% compliance isn't feasible. |
Nixpkgs is huge and broad. If the inputs are getting unwieldy, then you can say to sort if it improves comprehension, but I don't think this is true across the board. Also, you can convey that something is not a blocker (I usually say, I don't feel strongly about something). I think it's important for maintainers to have some "ownership" over the style of code they use. @SuperSandro2000 I agree it would be nice for some conventions to be well defined, but the nature of nixpkgs is that it's a "living document", in the packages it contains and the conventions it adheres to. Like @grahamc said, this is a step in the right direction, and overall improvement. Maybe one day we will be like elm, where the style is already determined for everyone, and adherence will be easy because any nix command will auto format your code. Until then, incremental improvement is always a good choice. |
Ordering by usage is the de facto ordering given to arguments. It's
logical, and makes finding argument usage easier. Putting lib first is
common in NixOS modules, so it's reasonable to mirror this in nixpkgs
proper. Additionally, it's not a package as such, has zero dependencies,
and can be found used anywhere in a derivation.
Motivation for this change
Following up on a conversation with @alyssais on IRC:
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)Ordering by usage is the de facto ordering given to arguments. It's
logical, and makes finding argument usage easier. Putting lib first is
common in NixOS modules, so it's reasonable to mirror this in nixpkgs
proper. Additionally, it's not a package as such, has zero dependencies,
and can be found used anywhere in a derivation.