-
Notifications
You must be signed in to change notification settings - Fork 6
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
Positional -> Named Parameters #1
Comments
I did consider using options instead of the parameters. And the decision was made based on two criteria:
To answer the first one, 4 parameters isn't that bad, though almost a border case. If I had to add 5, I would have gone with the options. I don't see any need in the future for adding another parameter, the current 4 ones seem comprehensive. In addition, I would be breaking compatibility with the existing protocol, if I were to change it now, then the biggest library to suffer from this would be pg-promise. The bottom line, if you need to call it frequently the way you showed in the example, then why not just wrap it up in a function? - function sequence(source, track) {
return spex.sequence(source, null, null, track);
} or, even more generic: function sequence(source, options) {
options = options || {};
return spex.sequence(source, options.dest, options.limit, options.track);
} UPDATE: Other advantages to consider:
Also, while your argument has some weight regarding method |
You've forgotten one criterion: how easy is it to read/comprehend/maintain? As mentioned in that article:
Now is the perfect time to make such a change. That's what the 0.x means.
Why not optimize for clarity and convenience first and then consider providing the positional variant as the wrapper for backwards compatibility? |
Actually, it doesn't mean it's a pre-release or something. It has been fully tested and released. It is production ready.
I was thinking about it, the other way round though, to provide a mirrored interface where all optional parameters are presented as P.S. I believe that what makes a good library is good documentation, is where I'm putting in a lot of effort. With good, easy-to-read documentation it isn't really that cryptic ;) |
This has been implemented in v.0.2.5 |
Thanks! |
@chocolateboy you are welcome, and thanks for the idea, it does look better now. |
I'm using
spex.sequence
on a project and it's working well, but the API is awkward to use IMO. Why not make the additional arguments tosequence
(and other spex methods) an options object rather than trying to shoehorn everything into positional args e.g.:Instead of:
How about:
?
The text was updated successfully, but these errors were encountered: