-
Notifications
You must be signed in to change notification settings - Fork 10
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
null prototype for returned values? #108
Comments
Null prototypes are a basic part of JavaScript at this point; if someone’s confused by console output that has it, then it’s a learning opportunity for them. |
There's precedent for this in the language (e.g. the |
Thanks @bakkot . The examples are good, and the I was wondering about a mention in the documentation and see there is for |
Other examples from @ljharb in nodejs/node#42675 (comment)
|
I wasn't actually expecting a case to turn up, let alone so quickly! |
Cough. Maybe extra code needed for unit tests of results. Found the hard way. 😓 |
Another reference of stumbles, this time looking for graphql issues: Top rated answer is:
|
or simply |
Yes, I cried a little when I saw the JSON answer again. 😢 |
Interesting, |
|
Took me a while to work out |
Having hit problems requiring time and effort to research to do something users may encounter, I am back to ambivalent about using null prototype. 😞 |
Object spread is The Way to shallow copy objects, and it’s what most users will reach for. I don’t think this is an actual problem. nonzero users are going to be confused no matter what we do; we should just do the safest thing and document well. |
In previous discussions (#33) we were wondering about using a Map or null prototype internally, but returning a normal object. I have minimal concerns about doing that. |
This is quite a good example of the complications. Yes, object spread is pretty awesomely useful for many situations. Likewise we also have But we are returning a null prototype object inside the result. The case I hit and showed in the PR is not fixed by shallow copy of the result. I launched into null prototype after it being suggested a second time and optimistic about the trade-offs. And it promptly blew up. So I'm pushing back and reevaluating the tradeoffs! |
I don't expect people to use the result object directly; i expect them to destructure it immediately. |
Far from convinced that null objects won't trip up multiple people, but done! Which makes null prototype one small step closer to routine... |
Agreed. I'm impartial either way, but do think this could be a slight annoyance to users expecting access to prototype methods (
I have only been destructuring in examples and tests for conciseness. However, in production I will likely always assign the result object directly to a variable (e.g. |
(I want a separate issue from #106, which is otherwise transparent improvements that do not affect the user experience.)
There are two potential benefits to using a null-prototype for
values
:toString
. (Although the usual convention for CLI is kebab-case liketo-string
which bypasses the issue.)The potential downside is confusing authors. Examples:
Related discussions:
(Paraphrased from one of discussions.) For comparison, by default Commander uses plain
{}
for storing the option values. I did also consider Map and null prototype at the time: tj/commander.js#1102 (comment))The text was updated successfully, but these errors were encountered: