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
Documentation prefer-string-slice
#2323
Comments
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, |
Another benefit we can mention is that |
Thank you for your fast answer. Are you accepting PRs to discuss the exact phrasings there or do you prefer to keep the discussion in the issue? |
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: