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
Editorial: Improve the explanation of split methods #2975
base: main
Are you sure you want to change the base?
Conversation
gibson042
commented
Dec 15, 2022
- Move note content describing special cases into the introductory <p>.
- Rename limit to substringLimit to indicate that it does not apply to the count of splits (as in some other languages).
- Eliminate horizontal scrolling in a code sample.
spec.html
Outdated
@@ -34306,17 +34306,17 @@ <h1>String.prototype.slice ( _start_, _end_ )</h1> | |||
</emu-clause> | |||
|
|||
<emu-clause id="sec-string.prototype.split"> | |||
<h1>String.prototype.split ( _separator_, _limit_ )</h1> | |||
<p>This method returns an Array into which substrings of the result of converting this object to a String have been stored. The substrings are determined by searching from left to right for occurrences of _separator_; these occurrences are not part of any String in the returned array, but serve to divide up the String value. The value of _separator_ may be a String of any length or it may be an object, such as a RegExp, that has a @@split method.</p> | |||
<h1>String.prototype.split ( _separator_, _substringLimit_ )</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is "limit" any less clear than "substringLimit" in a "string split" method?
I see your comment in the OP, but that isn't convincing to me, especially since most new JS devs probably have little to no experience with other programming languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some languages and libraries limit the count of splits while others limit the count of substrings. This rename provides a hint that ECMAScript is in the latter category, as opposed to e.g. Python (len("foo bar baz".split(" ", 1)) == 2
) and JMESPath (length(split('foo bar baz', ' ', `1`)) == `2`
) and Swift ("foo bar baz".split(separator: " ", maxSplits: 1).count == 2
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the difference; I'm skeptical that a) the parameter name in the specification is the source of that confusion, and that fixing it will have any impact, and b) that the majority of newcomers to JS will necessarily be familiar with languages in the former category.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not claiming that renaming a parameter in the specification will fix whatever confusion exists in the ecosystem at large, but doing so will at least prevent creating unnecessary additional confusion when reading the spec.
5908397
to
93e2ad4
Compare