-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: refine sample code on tokens of util/parseArgs #49263
base: main
Are you sure you want to change the base?
Conversation
b3095ba
to
f16a077
Compare
I don't have a strong opinion, just a reaction. The example is about using tokens. The old example code does not destructure much, and you see the tokens array and the token elements getting obviously named and processed, like both lines of:
That might be a positive rather than a negative for the purposes of a tokens example. (Disclaimer: I wrote the example.) |
Thank you to bring this up, I totally agree to have the However for case of |
Personally I find this snippet significantly harder to follow than the original, which should be a high priority for documentation. So I'm -1 on this change (as a contributor to parseArgs, but not a node maintainer). The original also has the advantage of being O(n) rather than O(n^2); if your concern is purely about best practices, you should definitely find a way to do this without a quadratic algorithm. |
To my knowledge, the
Performance checklist:
are you looking for Premature Optimization? |
I'm not saying that it will actually be slow enough to matter in this instance. I'm saying that if you want to encourage good practices in general, you should not have a sample where there is a If your concern is not about what general practices this code is fostering, I don't understand why you're suggesting a change at all. All the PR description says is "avoid mutations / side-effects", which is a principle some people like to follow. To me, "avoid quadratic algorithms" seems like a much more important principle. |
For interest the PRs that led to tokens feature and docs are:
(Over 180 comments, but of course that was for the full feature and not just the example.) |
@bakkot |
Back to Dec 2018, the v8 team had this article: Speeding up spread elements, it's about massive performance improvement of spread on Arrays where require nothing changes from end user, I wander if one day the Object literals got similar treatment, does it shake up any stands on O(n^2)? I don't believe there is no room for syntax like I don't have anything on this PR left, feel free to close as you please. |
Reduce mutations / side-effects on the code snippet in docs.