-
Notifications
You must be signed in to change notification settings - Fork 16
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
Argument order for locks.acquire #19
Comments
@domenic - what do you think? We've got two conflicting precedents here - putting callbacks last, and putting options last. |
Yeah, I noticed this before. I guess I do lean toward callback-last. Preferably with an overload so you can omit the options, I guess. |
Are dictionaries and callbacks distinguishable in WebIDL parlance? overloading still hurts my brain... i.e. is this valid WebIDL ? interface LockManager {
Promise<any> acquire((DOMString or sequence<DOMString>) scope,
LockRequestCallback callback);
Promise<any> acquire((DOMString or sequence<DOMString>) scope,
optional LockOptions options,
LockRequestCallback callback);
}; |
Well, optional arguments before the end is not valid Web IDL, so that's a minor bug... They are not distinguishable, but overloads allow you to make decisions based on the number of arguments passed, instead of on distinguishability. This is usually bad practice, but it seems like the best option here... |
Whoops, copy/pasta. Removing interface LockManager {
Promise<any> acquire((DOMString or sequence<DOMString>) scope,
LockRequestCallback callback);
Promise<any> acquire((DOMString or sequence<DOMString>) scope,
LockOptions options,
LockRequestCallback callback);
}; And... I guess argument count trumps distinguishability? I'll give this a whirl in Blink at least. |
Thanks - yes, code is much more readable this way. Updated the readme, proto spec, idl, and added an FAQ item contrasting the two versions. |
🎉 Thank you very much! |
(while it may be worse for WebIDL) I think it'd be better if the options bag preceded the callback. JS code is easier to read when functions take at most one callback, which is the last argument.
The example below is lifted from the explainer. Baseline:
This proposal:
So, please reconsider the argument order.
The text was updated successfully, but these errors were encountered: