-
-
Notifications
You must be signed in to change notification settings - Fork 14.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
[Discussion] Should "unused code" that are "useful" in a file be removed (or commented out)? #331085
Comments
Note: nixf-tidy currently lacks ignoring flags (in comments), but this is a planned feature. |
This comment was marked as resolved.
This comment was marked as resolved.
Thank you for bringing this up! |
Hi, I'm trying to manually get rid of most unused arguments (#313981). So far removed about 1700 of them (2000 if you count the opened pr). I use deadnix to find them, and it also have the same issue with |
This comment was marked as off-topic.
This comment was marked as off-topic.
My 0.5 NOK:
|
Having to comment the code is IMO the solution we definitely do not want. We have git to recover the code if it was removed. Then the question remains if we want to globally drop unused code. |
On a slightly philosophical note: Tools should be there to serve and accommodate people. Therefore as long as it can be implemented within reasonable effort, questions should always be answered from the perspective of "what do the humans want", not "what has a simple implementation". We live in a messy world, navigating it necessarily imbues a lot of complexity. |
We have many instances of packages maintained by a single silent-retired being - see #290642. Further, I could argue that the biggest barrier to being a Nixpkgs maintainer is having a GitHub account. To not derail this conversation, I refer to this link: #327779 |
Main pointTidying is a needed and necessary job. Following on from @piegamesde's philosophical point, humans do better work when non-essential details are removed from view, and inactive code is as non-essential as it gets. Yet the work of tidying often turns into toil. If a tool helps with this goal, it's helping us bridge between two good aims which otherwise would be in tension. Case 1️⃣Removing the Case 2️⃣On this specific case: why should every aliases file re-implement a similar function? Extract the helper to some more relevant location, then use it when needed. On the general case, if there's some social expectation when editing a file, having a comment seems like the right place to land that, and having code inside that comment is no bad thing. The most important thing is to communicate the social expectation. Don't just comment out code and leave the social expectation of what to do with that code out, please! Case 3️⃣I feel quite complicated about this case. Behavior that "lights up" if you pass an argument that's not in the parameters (as shown by In Python, I advocate avoiding On the other hand, we live in a complicated world in nixpkgs, and it's quite certainly the case that there will of necessity be action at a distance as two orthogonal features are combined together. The use of |
This part of the supporting view is weak. The linked example (#330589 (comment)) and potential problems do not apply to the mentioned unused arguments To be clear, the pattern is to provide a default value for an argument ( |
So maybe this should be identified in another tidy check. |
So the fix here I guess is:
I would like to remind everyone that inclyc is currently unable to escape due to some serious matters, so there may not be any progress this week or next week. At present, CI is still working relatively well and can detect more than 10 incorrect writings a day, so the status quo should be maintained for the time being. For the few PRs that have errors due to 2 and 3, if there is nothing inappropriate, please remind them to ignore the errors first. |
This comment was marked as resolved.
This comment was marked as resolved.
Related NixOS/nixpkgs#331085 Fixes: #558 --------- Co-authored-by: Yingchi Long <[email protected]>
- remove meta with lib (NixOS#208242) - use with lib.maintainers (NixOS#331085)
- remove meta with lib (NixOS#208242) - use with lib.maintainers (NixOS#331085) - remove unnecessary trivial nix-update-script for Python packages
Was reminded of the Case 3 situation about default values while working on one of my PRs and wanted to write down some thoughts. (Maybe there's a more appropriate place to post this, but I couldn't find it.) I've realized that there's an alternative that is much simpler to mentally process than the Let's say you wanted to write a wrapper for Instead of doing { stdenv }:
{
a ? "a_default",
b ? "b_default",
}@args:
stdenv.mkDerivation args which wouldn't work, since the defaults don't get inherited by args, { stdenv }:
_args:
let
args = {
a = "a_default";
b = "b_default";
} // _args;
in
stdenv.mkDerivation args In my experience it's simply wrong to combine Note: this example didn't have any required attributes. |
Case 1. unused with in maintainer list
Removing
with lib.maintainers; [ ]
because nixf-tidy complaints aboutwith
being unused. #330664Opposed view: #330664 (comment) A package should have maintainers. A package that does not have a maintainer is a special case. Keeping this
with
can help reduce diff.Supporting view: #330232 (comment) An exception should not be made here, it would make the rule unnecessarily complex.
Case 2. Unused helper functions in files for enumeration
In an enumerated file, a function that may be used needs to be removed or commented out because there is no use case for the time being, in order to pass nixf-tidy's check. https://github.com/NixOS/nixpkgs/pull/331017/files
Opposed view: Not being used is temporary, being used is normal, and the placed function has a documentation functionality.
Case 3. Unused argument in commonly used builder function
Arguments such as
pname
,version
,src
are not used directly, but are passed in as{ ... }@args
andargs
is further passed to underlying builder function.nixf-tidy
suggests these arguments should be deleted. #330589Opposed view: They can capture missing arguments as early as possible, and have certain documentation functionality, because this information can be obtained using
functionArgs
.Supporting view: #330589 (comment) They can cause problems, such as making arguments with a default value to be actually undefined (example: in
doInstallCheck = attrs.doCheck or true;
,doInstallCheck
istrue
ifdoCheck
is not passed as an argument, even ifdoCheck
defaults tofalse
); there are better ways to write them;functionArgs
is not good documentation and should be replaced by doc-comments in the future.CC @inclyc @SuperSandro2000 @AndersonTorres @piegamesde @Mic92 @mweinelt @jian-lin
The text was updated successfully, but these errors were encountered: