Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Percent literal brackets #526
In general I agree with the percent literal styles.
%w[Ruby Javscript Python]
%w(Ruby Javscript Python)
I am very interested in the reason for the decision.
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.
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.
Mar 10, 2016
referenced this issue
Apr 23, 2016
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.
referenced this issue
Oct 14, 2016
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...