-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Explain why so many builtins
are available in global scope
#7290
Comments
Disagree. This is going to unnecessarily break downstream code outside of nixpkgs. Because these shortcuts are available, people are using them. I think it is also imperative that the Nix language stays backwards as much as possible and it is unnecessary to jeopardize this by removing builtins. Your recommendations seem fine. We can probably go a similar way as with the URL syntax and add an experimental feature for warnings if you violate those recommendations. Removing the builtin aliases that start with two underscores seems like a no brainer (if some research was done if there's real world usage), but is actually a bit tricky:
|
I'd think these as unreliable implementation details.
IRCC, identifiers starting with It's good to discourage undocumented identifiers starting with EDIT: I just find there's a |
Actually very reliable: Overloading Ever since Additionally, behavior that is not documented is still known—if everything that is not documented about Nix were to be changed arbitrarily, a lot of actual expressions would break. I would like to see Nix be documented as the pragmatic, 20 year old project that it is rather than have it changed according to some preconceived notion what it should have been first in order to be documented.
Sure, going forward. Still, a better practice is no reason to unnecessarily break stuff—this is all I want. We don't need to document and bless this behavior, but breaking it needs careful consideration and should be orthogonal to documenting Nix.
But is that documented…? :) |
I get you point about compatibility, but I don't really like this much python-ish dynamic, especially to overload buitlins, since it can hurt readability (for a bare file without context) and performance. It makes nix hard to cache the preprocessed source files. |
True, but this is due to
Since overloading is only possible via non-dynamic scope, it can be implemented very efficiently—at least if you do a static scope analysis before dispatching which even C++ Nix can to an extent as far as I'm aware. You only need to have a function call if the overloading identifier has been re-defined in scope which can be known statically (or semi-statically with |
I did a little dive into |
Problem
As a documentation maintainer I want to guide users into understanding the Nix language.
What's confusing is that quite many
builtins
are also available in the global scope for no apparent reason, although the manual says that this global attribute set is there to avoid polluting the namespace:abort
baseNameOf
builtins
(yes, recursively)derivation
derivationStrict
dirOf
fetchGit
fetchMercurial
fetchTarball
fromTOML
import
isNull
map
placeholder
removeAttrs
scopedImport
throw
toString
@sternenseemann: a list including
__*
builtinsIt would not suffice saying that these are for backwards compatibility, as some of them were introduced after Nix 2.0.
Checklist
Proposal
Be deliberate about it. Only make the following
builtins
available globally and tell why:For general convenience:
import
map
toString
For convenience when testing and debugging:
abort
throw
derivation
There may be another group for backwards compatibility, but that should, with appropriate grace periods:
The text was updated successfully, but these errors were encountered: