Hacker News new | ask | show | jobs
by 22c 2307 days ago
Not every rule has a reason, some of it is just "because style guide" and if you try to look up the rationale there, you'll find none.

Classic example is Perl style %w(literal arrays) vs ['traditional', 'arrays'].

> Prefer `%w` to the literal array syntax when you need an array of strings

Which was introduced[1] into the style guide nearly 9 years ago with practically no reasoning. Prefer `%w` because why exactly?

[1] https://github.com/rubocop-hq/ruby-style-guide/commit/b27eff...

2 comments

I prefer the brackets to parens because it makes it more clear at a glance that the result is an array.
Shorter. Different code coloring. I prefer %w where possible with or without Rubocop.