-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Percent literal brackets #526
Comments
I agree this is a reasonable usage of square brackets. |
I am a little surprised. I expected some kind of refusal. |
Like most projects, the guide is never truly finished. :-) As I've said many times - I don't view myself as its author, but just its editor and I'm always open to reasonable suggestions.
Yes. |
O.K. Then I'll send a pull request and let's see, what the community will think about it. |
Some comments about percent-literal brackets:
|
I would like add a vote in favor of the use of square brackets when referencing or inferring a reference to an array. In my humble opinion parenthesis imply params. If %w is a function and the elements of an array are parameters then parens make sense, otherwise brackets seem to convey the message with natural clarity. |
I am not a frequent user of this notation myself, but I can imagine the distinction between a bare array literal and these serves a purpose. If I'm looking at the trailing end of a percent literal like this:
I must first notice the missing comma, and then follow the line to the beginning to see that it's actually a percent literal, and not a bare array literal with a syntax error. Now, this is completely speculative, and I am slightly in favour of the change myself, but thought I'd try to argue for the other side for a balanced discussion. 😀 |
I do use the percent literal arrays quite often and I disagree with this change. As @bbatsov does, I think square-bracket percent literals for arrays are perfectly reasonable, but I think rounded brackets are just as reasonable and that's where my personal preference lies. I don't think there's enough of a distinction between a normal array and the square bracket percent-literal array. It makes sense to me that we have an array shorthand in-line with JSON in Both positions are personal preference, and as far as I've seen over the years the rounded brackets is the more popular option. Here are the stats on usage of 3 styles in the Rails codebase:
By no means do I think of the Rails codebase as a style guide, but it's probably a decent indicator of popularity. So since there's no overwhelming majority one way or the other - and if anything a majority on the side of rounded brackets - I'm not sure why we would change it. I appreciate that other people have different personal preferences (as I have plenty that differ from this style guide), but that's why we have the ability to configure options like this in RuboCop... |
In light of #563, can this be closed? |
Sure :) |
…nfiguration to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
…tion to match Style Guide update The Style Guide was changed to [prefer square brackets for word- and symbol array literals](rubocop/ruby-style-guide#526). This change brings RuboCop's config back in line.
In general I agree with the percent literal styles.
It clearly makes sense to avoid other delimiters than brackets for escaping reasons.
Additionally I would like to question using squared brackets for Array literals is a bad practice, like:
compared to:
I am very interested in the reason for the decision.
From my point of view it expresses the Array character way more. Please let us discuss it.
My thoughts about percentage notations
The text was updated successfully, but these errors were encountered: