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: tweak the coding conventions #51113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 but would rather not give the impression there is some sort of Tweag style guide influencing this :)
213b220
to
ca6c692
Compare
Encouraging to put container elements on their own lines to minimize diffs, merge conflicts and making re-ordering easier. Nix doesn't suffer the restrictions of other languages where commas are used to separate list items.
ca6c692
to
80cff57
Compare
oops, typo :) |
This pull request has been mentioned on Nix community. There might be relevant details there: https://discourse.nixos.org/t/on-nix-expression-formatting/1521/16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
elem1 | ||
elem2 | ||
elem3 | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you suggest for this common case?
{
list =
[
elem1
elem2
elem4
] ++ lib.optionals stdenv.isDarwin [ elem4 elem5 ];
}
I like the extra indentation, since it needs top-level keys easy to spot, but if the [
is on the same line as the =
, that doesn't really make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
list = [
elem1
elem2
elem3
] ++ lib.optionals stdenv.isDarwin [
elem4
elem5
];
}
looks good to me, though it is kind of similar to
someParameter = [ {
foo = bar;
baz = quux;
} {
some = more;
stuff = here;
} ];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your version is fine.
I only really care about the mechanics of what happens when maintaining the code. So when the code evolves, if elem{1,2,3}
are on distinct lines with no []
they are easily movable / commentable / sortable. A soft rule would be that if there are more than 2 elements in a list it's better to use the multi-line notation.
A variation of your example I have seen which is also quite nice is:
{
list =
[
elem1
elem2
elem3
]
++ lib.optionals stdenv.isDarwin [ elem4 elem5 ]
++ lib.optionals stdenv.isLinux [ elem6 ]
;
}
Again here the same logic applies: each of the extra ++
is easily movable without having to worry of moving the ;
around.
Tweaks the coding style guide to encourage putting container elements on their own lines.
This minimizes diffs, merge conflicts and makes re-ordering of those elements easier.
Nix doesn't suffer the restrictions of other languages where commas are
used to separate list items.
Motivation for this change
Discussion at https://discourse.nixos.org/t/on-nix-expression-formatting/1521/15
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)