doc: refine sample code on tokens of util/parseArgs#49263
doc: refine sample code on tokens of util/parseArgs#49263imcotton wants to merge 3 commits intonodejs:mainfrom
Conversation
b3095ba to
f16a077
Compare
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 |

Reduce mutations / side-effects on the code snippet in docs.