You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I can find proof for that statement for String#substr(), I can't seem to find any for String#substring(). Especially the "more popular" part is confusing to me. Was there any survey made about this? I was not able to find any. If there was, there should be a link to give more weight to this argument.
Unlike others, this rule feels very arbitrary in its reasoning why one should use it. I'd suggest a more thoughtful explanation here.
One suggestion, that came up in a discussion with a colleague, is to double down on the "Array counterpart" point:
The argument should be that strings are simply arrays of characters and thus can be treated like them (spread, index accessor, ...). This makes it much easier to make good arguments in favor of using this rule in projects. This could lead to an increase of adaptability (although I doubt it).
Additional Info
I'm not against this rule as is. My reasoning for this issue comes from a (previously mentioned) discussion with a colleague who questioned the integration of the rule. I've sent him the rules documentation as they usually have pretty good descriptions of why you should (or shouldn't) adapt them. They pointed out the missing source for statements made which I had to agree with.
The text was updated successfully, but these errors were encountered:
While I didn't add the note about popularity and I don't have any proof of this. From my experience of reading a lot of open source code, .slice() is definitely more common. But I do agree we should have some actual proof of this.
Description
The rule
prefer-string-slice
claims in it's documentation:While I can find proof for that statement for
String#substr()
, I can't seem to find any forString#substring()
. Especially the "more popular" part is confusing to me. Was there any survey made about this? I was not able to find any. If there was, there should be a link to give more weight to this argument.Unlike others, this rule feels very arbitrary in its reasoning why one should use it. I'd suggest a more thoughtful explanation here.
One suggestion, that came up in a discussion with a colleague, is to double down on the "Array counterpart" point:
The argument should be that strings are simply arrays of characters and thus can be treated like them (spread, index accessor, ...). This makes it much easier to make good arguments in favor of using this rule in projects. This could lead to an increase of adaptability (although I doubt it).
Additional Info
I'm not against this rule as is. My reasoning for this issue comes from a (previously mentioned) discussion with a colleague who questioned the integration of the rule. I've sent him the rules documentation as they usually have pretty good descriptions of why you should (or shouldn't) adapt them. They pointed out the missing source for statements made which I had to agree with.
The text was updated successfully, but these errors were encountered: