Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upFunction implicit lengths should not include optional arguments #264
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domenic
Dec 17, 2015
Member
It seems better to have explicit lengths everywhere and remove this guidance.
|
It seems better to have explicit lengths everywhere and remove this guidance. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 17, 2015
Member
I would be 1000% in favor of that! However, it's gotten some pushback previously in the category of "we prefer to avoid redundancy".
|
I would be 1000% in favor of that! However, it's gotten some pushback previously in the category of "we prefer to avoid redundancy". |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 17, 2015
Member
(It's also worth noting that implementors have often gotten the implicit length wrong, and have even been confused by the current wording, assuming the change I recommend here as fact.)
|
(It's also worth noting that implementors have often gotten the implicit length wrong, and have even been confused by the current wording, assuming the change I recommend here as fact.) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Dec 17, 2015
Member
I don't care how we resolve the redundancy really. If people want to make everything explicit I'm fine with that.
The issue here, to be clear, is about what the length of, say, Map is, which has one optional parameter and no explicit length specification. The current language says it should be 1, but it should probably be 0. Edge and Chrome implement 0. I think the current language is just a bug.
|
I don't care how we resolve the redundancy really. If people want to make everything explicit I'm fine with that. The issue here, to be clear, is about what the length of, say, Map is, which has one optional parameter and no explicit length specification. The current language says it should be 1, but it should probably be 0. Edge and Chrome implement 0. I think the current language is just a bug. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Firefox and Safari also implement |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
anba
Dec 17, 2015
Contributor
I don't mind if the default length computation is switched from "including optional parameters." to "not including optional parameters." in Ch.17. But explicit length definitions everywhere should not be applied for the reasons outlined in #104.
|
I don't mind if the default length computation is switched from "including optional parameters." to "not including optional parameters." in Ch.17. But explicit length definitions everywhere should not be applied for the reasons outlined in #104. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
The value of the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Dec 18, 2015
Member
The intent was that new built-ins would follow the same length determination rules as used for ES defined functions, except if the function signature was very similar was very similar to some pre-ES6 built-in that had a different explicitly assigned length value.
For a while in ES6 draft we tried to use ES-style signatures (default values indicating options and rest) for all built-ins but it seemed a poor match to the pseudo-code and there were too many length exceptions for pre-ES6 functions. So we reverted to ES3/5 signature conventions.
Not that even with you give every built-in an explicit length you still probably want to state the default rule somewhere so that future spec. writer have some guidance when assigning lengths for new built-ins.
|
The intent was that new built-ins would follow the same For a while in ES6 draft we tried to use ES-style signatures (default values indicating options and rest) for all built-ins but it seemed a poor match to the pseudo-code and there were too many Not that even with you give every built-in an explicit length you still probably want to state the default rule somewhere so that future spec. writer have some guidance when assigning lengths for new built-ins. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 18, 2015
Member
So it sounds like there is complete consensus that the language in Chapter 17 should change to exclude optional parameters from the length by default - and there is not consensus about whether everything should have an explicit length or not.
If this seems accurate and there are no objections, I'll prepare a PR that updates the language in Chapter 17, and I'll go through every function in the spec in an attempt to minimize explicit length references while matching implementations (the current state).
|
So it sounds like there is complete consensus that the language in Chapter 17 should change to exclude optional parameters from the length by default - and there is not consensus about whether everything should have an explicit length or not. If this seems accurate and there are no objections, I'll prepare a PR that updates the language in Chapter 17, and I'll go through every function in the spec in an attempt to minimize explicit length references while matching implementations (the current state). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bterlson
Dec 18, 2015
Member
@ljharb I would accept such a PR :) Depending on how much normatively changes (I suspect not much) we may or may not want to get committee feedback before pulling it in. But I suspect the normative changes will be minimal.
|
@ljharb I would accept such a PR :) Depending on how much normatively changes (I suspect not much) we may or may not want to get committee feedback before pulling it in. But I suspect the normative changes will be minimal. |
ljharb commentedDec 17, 2015
http://tc39.github.io/ecma262/#sec-ecmascript-standard-built-in-objects
Most builtin functions that don't mention an explicit length (except for legacy ones like
ObjectandDate) do not include optional parameters in the function'slengthproperty. In addition, all of the explicit lengths seem to follow the same guideline.In addition,
function foo(a, b = 3) {}.lengthgives 1 - default arguments are not included.The above note should be changed to say: "not including optional parameters.", and if this would meaningfully affect the implicit lengths of any existing functions, then those legacy functions should have explicit lengths added. This change can also remove any explicit lengths that match the changed text.
If everyone is in agreement, I'll be happy to prepare a PR.