Style Guide vs

The Ruby Style Guide (https://github.com/bbatsov/ruby-style-guide)
unambiguously promotes the
%w(foo bar baz)
style of string arrays over the more traditional
['foo', 'bar', 'baz']

I am coming to believe that I am in disagreement with the style guide.
How do others feel about it? I'm generally a big believer in keeping
one's code in sync with others' work and thus readable to the larger
audience. But I find the %w to be jarring when dealing with a data
structure that has a general case, but specifically different syntax
for particular types. I feel doubly so in that Ruby usually doesn't
care about types.

Opinions?

Then open an issue on it. I think it's pointless and dislike the extra
typing myself. We're not Java or Python, no point in cargo culting
verbosity because it makes people feel more comfortable.

···

On Sep 13, 2015 6:02 PM, "NBarnes" <nbarnes@gmail.com> wrote:

The Ruby Style Guide (https://github.com/bbatsov/ruby-style-guide\)
unambiguously promotes the
%w(foo bar baz)
style of string arrays over the more traditional
['foo', 'bar', 'baz']

I am coming to believe that I am in disagreement with the style guide.
How do others feel about it? I'm generally a big believer in keeping
one's code in sync with others' work and thus readable to the larger
audience. But I find the %w to be jarring when dealing with a data
structure that has a general case, but specifically different syntax
for particular types. I feel doubly so in that Ruby usually doesn't
care about types.

Opinions?

I agree. I use the ['foo', 'bar', 'baz'] myself. I like the
consistency between the way the array is represented and what I typed.

Like this from IRB:

["foo", "bar"]

=> ["foo", "bar"]

over this:

%w{foo bar}

=> ["foo", "bar"]

It's more than typing a few extra characters, I just get this mental
"hiccup" reading with the %w

This goes double when considering the next idea in the style guide: %i{foo bar}

So now that single character, the "w" or the "i", is the difference
between ["foo", "bar"] and [:foo, :bar]. I don't want to use my brain
to process this, even if it's a minor calculation. I like "smooth"
Ruby, where what I see is what I get back.

A style guide is not law. The general attitude of the document is
true and a good rule-of-thumb, and it will keep you in line with most
Ruby devs. But if you're on a team, I'd recommend forking the guide
and edit it to conforming to the consensus of your team.

Darren

Darren Cauthon
darren@cauthon.com

···

On Sun, Sep 13, 2015 at 8:01 PM, NBarnes <nbarnes@gmail.com> wrote:

The Ruby Style Guide (https://github.com/bbatsov/ruby-style-guide\)
unambiguously promotes the
%w(foo bar baz)
style of string arrays over the more traditional
['foo', 'bar', 'baz']

I am coming to believe that I am in disagreement with the style guide.
How do others feel about it? I'm generally a big believer in keeping
one's code in sync with others' work and thus readable to the larger
audience. But I find the %w to be jarring when dealing with a data
structure that has a general case, but specifically different syntax
for particular types. I feel doubly so in that Ruby usually doesn't
care about types.

Opinions?

I think you shouldn't be concerned with readability for the whole
community. I'd suggest adjusting the style guide (and linting tools) to fit
your and your's team preferences. It's more important to maintain internal
consistency within the project and enforce rules from contributors. The
style guide you linked can serve as a basis for the style that fits your
preferences and project needs. You don't have to agree with all the rules.
What's more, some of them are based on incorrect assumptions (at least
according to my research; see [1] for an example)

[1] Drop rule prohibiting passing exception instances to fail · Issue #395 · rubocop/ruby-style-guide · GitHub

···

On Mon, Sep 14, 2015 at 3:01 AM, NBarnes <nbarnes@gmail.com> wrote:

The Ruby Style Guide (https://github.com/bbatsov/ruby-style-guide\)
unambiguously promotes the
%w(foo bar baz)
style of string arrays over the more traditional
['foo', 'bar', 'baz']

I am coming to believe that I am in disagreement with the style guide.
How do others feel about it? I'm generally a big believer in keeping
one's code in sync with others' work and thus readable to the larger
audience. But I find the %w to be jarring when dealing with a data
structure that has a general case, but specifically different syntax
for particular types. I feel doubly so in that Ruby usually doesn't
care about types.

Opinions?

I remember a day, many years ago, when devs-on-high passed down a rule
that the team must put my C# curly braces.

public void Blah()
{
}

instead of

public void Blah(){
}

Oooooooohhhh, that made me so mad! So I'd argue the point with
anybody who cared. Or they'd argue with me, a big pod of of
twenty-somethings fighting these passive-aggressive battles inside the
codebase.

I'm a little older, and I see how dumb this is.

The neat thing about modifying these style guides for team preferences
is that they (1) settle the point, (2) they provide a tie-breaking
vote. Half the team wants [1, 2, 3].each { |e| puts e }, the other
half wants [1, 2, 3].each{|e| puts e}... first wins, we agree to work
together, now sit down, comply, and code. Anybody does it wrong, just
point at the concrete document. There better be a double-darn good
reason for anybody to pop a PR against that document, too, as they'll
be responsible for any team turmoil.

I think of the small Ruby teams I've worked in... years of not
talking about syntax. It's great.

Darren
Darren Cauthon
darren@cauthon.com

···

On Mon, Sep 14, 2015 at 10:30 AM, Greg Navis <contact@gregnavis.com> wrote:

I think you shouldn't be concerned with readability for the whole community.
I'd suggest adjusting the style guide (and linting tools) to fit your and
your's team preferences. It's more important to maintain internal
consistency within the project and enforce rules from contributors. The
style guide you linked can serve as a basis for the style that fits your
preferences and project needs. You don't have to agree with all the rules.
What's more, some of them are based on incorrect assumptions (at least
according to my research; see [1] for an example)

[1] Drop rule prohibiting passing exception instances to fail · Issue #395 · rubocop/ruby-style-guide · GitHub

On Mon, Sep 14, 2015 at 3:01 AM, NBarnes <nbarnes@gmail.com> wrote:

The Ruby Style Guide (https://github.com/bbatsov/ruby-style-guide\)
unambiguously promotes the
%w(foo bar baz)
style of string arrays over the more traditional
['foo', 'bar', 'baz']

I am coming to believe that I am in disagreement with the style guide.
How do others feel about it? I'm generally a big believer in keeping
one's code in sync with others' work and thus readable to the larger
audience. But I find the %w to be jarring when dealing with a data
structure that has a general case, but specifically different syntax
for particular types. I feel doubly so in that Ruby usually doesn't
care about types.

Opinions?

On the other hand %w and %i come out of necessity. Writing arrays of words
or symbols is common enough to warrant special syntax that frees you from
writing some much punctuaction, and read the items cleanly.

And then some people (me included) prefers the most concise idiom the
language offers. So, I never write an array of words using the bare array
syntax, I never write a string with backslashes if I can avoid it chosing
an alternative syntax, etc.

I write this reply not to convince you that you should change your mind.
Not at all, I totally understand you prefer not to use them because of the
reasons you explained. But reciprocally, I present you arguments so that
you can see other people see it the other way around, and by the same
principle that's also fine.

And that's why they end up in a style guide, a style guide reflects the
preferences of whoever maintains it. Those are preferences, you arrive to
the guide because you like the choices, not because there is a logical path
towards them. There isn't.

And thus, patching a style guide to change it to your own's preferences...
you can do it of course, but if it is there is probably because the
maintainer made a conscious decision about its inclusion and you are not
going to convince them (as you would not convince me).

The difference between %w and the explicit use of [ ... ] is probably not more
than bikeshedding. One can argue that %w and the other short-hand forms reduce
the potential for syntax errors, but that's about all.

Many style guides exist, and they are not law unless one wants to contribute
to the project that uses them. If the OP dislikes the % syntax, why not opt
out of them for one's own projects?

      --- Eric

···

On Monday 14 September 2015 09:47:16, Darren Cauthon <darren@cauthon.com> wrote:

I agree. I use the ['foo', 'bar', 'baz'] myself. [...]

A style guide is not law.

I believe the main argument is "less things to write, and less things your
brain needs to parse", because when you read

    %w(foo bar baz zoo)

there are no quotes and commas adding "noise". Write and read easily. So it
is about clean code, rather than probability of a mistake.

(Again, not saying you have to agree the code is cleaner, or that cleaner
goes higher than uniform syntax, etc.)

···

On Mon, Sep 14, 2015 at 5:07 PM, Eric MSP Veith <eveith@wwweb-library.net> wrote:

On Monday 14 September 2015 09:47:16, Darren Cauthon <darren@cauthon.com> > wrote:

> I agree. I use the ['foo', 'bar', 'baz'] myself. [...]
>
> A style guide is not law.

The difference between %w and the explicit use of [ ... ] is probably not
more
than bikeshedding. One can argue that %w and the other short-hand forms
reduce
the potential for syntax errors, but that's about all.