Skip to content

rephrase best practices for clarity#790

Merged
proofconstruction merged 1 commit intoNixOS:masterfrom
wamirez:master
Nov 6, 2023
Merged

rephrase best practices for clarity#790
proofconstruction merged 1 commit intoNixOS:masterfrom
wamirez:master

Conversation

@wamirez
Copy link
Copy Markdown
Member

@wamirez wamirez commented Nov 6, 2023

Added some changes to source/guides/best-practices.md.

  • Removed a bullet point.
  • Simplified rec example.

@wamirez wamirez requested a review from a team as a code owner November 6, 2023 16:30
Copy link
Copy Markdown
Contributor

@proofconstruction proofconstruction left a comment

Choose a reason for hiding this comment

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

Reviewed in documentation team meeting. This simplifies the section.

@proofconstruction proofconstruction merged commit 51e43e3 into NixOS:master Nov 6, 2023
- It's possible to introduce a hard to debug error `infinite recursion` when shadowing a name, the simplest example being `let b = 1; a = rec { b = b; }; in a`.
- Combining with overriding logic such as the [`overrideAttrs`](https://nixos.org/manual/nixpkgs/stable/#sec-pkg-overrideAttrs) function in {term}`Nixpkgs` has a surprising behaviour of not overriding every reference.
A common pitfall is to introduce a hard to debug error `infinite recursion` when shadowing a name.
The simplest example for this is: `let a = 1; in rec { a = a; }`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
The simplest example for this is: `let a = 1; in rec { a = a; }`.
The simplest example for this is: `let a = 1; in rec { a = a; }`

With a colon in between we probably don't need the full stop, as that tends to interfere with reading the expression.

Alternatively, but that could give it too much emphasis right before the tip:

Suggested change
The simplest example for this is: `let a = 1; in rec { a = a; }`.
The simplest example for this is:
```{code-block} nix
let a = 1; in rec { a = a; }
```

We may want to add <details> because it may not be apparent what's trivially weird about it:

One might expect that the value assigned in the attribute set is taken from the surrounding let binding, but names from the rec scope take precedence.

@nixos-discourse
Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-11-06-documentation-team-meeting-notes-92/35243/1

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.

4 participants