Single quotes are clean, easier to read, and using them is preferred #660

Merged
merged 1 commit into from Mar 20, 2014

Projects

None yet

6 participants

@garysweaver
Contributor

This PR is to bring the use of single vs. double quotes in Gemfile back for consideration.

What rubygems.org is currently providing as an example for Gemfile inclusion is the style promoted in GitHub's style guidelines but is inconsistent with its own Gemfile and many of the Gemfiles in rubygems projects. I'll provide some other reasons why this change should be considered, though I know it is currently still a point of contention with many.

According to the Ruby Style Guide, although "The second style (always using double-quotes) is arguably a bit more popular in the Ruby community", it says, "The string literals in this guide, however, are aligned with the first style (using single-quotes)."

Both IDea and RubyMine flag non-interpolated strings that don't contain escape characters and that are in double-quotes.

From a speed-of-syntax-processing standpoint, it may not matter which is used, but this is not a point in favor of use of double-quotes for non-literal strings. Historically in Ruby (going way back), single-quotes have been the form to use for literal strings; they have not been deprecated. Single-quotes are used for a similar purpose in bash, perl, etc., so they should be familiar to many. Use of single-quotes implies that a String is literal; this is almost always the case within a Gemfile, and it certainly is the case here. To use double-quotes would imply that there is a possibility of interpolation or escape characters that does not exist for the example provided.

It is argued that, if you use double quotes, you would not have to go back and change them when you require interpolation or escape characters. This seems to imply that using them is an energy and time-saving technique. But, with commonly-used key layouts, you have to press shift and the quote key to enter a double-quote vs. only the quote key. If you compound that additional time and energy to press the shift key, double-quotes may waste effort. :) But, in all seriousness, there is very little chance in a Gemfile that either interpolation or escape characters would be needed for the gem name or version strings, and certainly not for the examples provided.

Finally, each additional mark caused by double-quotes is visual noise. Using single quotes in the Gemfile will clean up and promote readability.

Thank you for your consideration.

@garysweaver garysweaver Single quotes are clean, easier to read, using them is the preferred …
…of both styles presented in ruby-style-guide for non-interpolated strings, and some well-used style checkers like IDea/RubyMine flag non-interpolated strings with double-quotes
84cbece
@sferik
Member
sferik commented Mar 20, 2014

Personally, I tend to use single quotes in my Gemfiles and am (more or less) an adherent to the Ruby Style Guide. However, on this point, I don’t have a strong opinion, so I’ll defer to @qrush.

@qrush
Member
qrush commented Mar 20, 2014

If you feel strongly about this, I'm up for trying it. I don't think it matters in the long run, but these are pretty good reasons.

@sferik sferik merged commit f78b732 into rubygems:master Mar 20, 2014

1 check passed

default The Travis CI build passed
Details
@sferik
Member
sferik commented Mar 20, 2014

🚢 Deployed!

@garysweaver
Contributor

Thanks!

@joshsusser

Sorry I missed a chance to comment earlier. I oppose the single-quote default. The arguments @sferik makes for using single-quotes in the Gemfile in particular are overshadowed by the benefits of a consistent style throughout the codebase, so the main question should be what the style is for the project as a whole. If your argument is that double-quotes have more visual noise, you probably have a problem with your font face. (That's not snark, I'm serious.) And I believe that a double-quote default is useful in an OSS project, for just the reason Erik referred to: adding an interpolation to a single-quoted string requires changing the quotes, and that adds noise to diffs, which IMO is a heavier cost than visual noise in the static source. This may seem a minor point, but the double-vs-single quote signal that a string includes an interpolation is redundant with the presence of #{...} in the string, and every decent editor makes that obvious with syntax highlighting. I almost never regret defining a string literal with double-quotes, but often find myself regretting someone else's single-quoted string as I have to change it. I don't want to fight about this, but just wanted to present a counter-argument to @sferik, and to weigh in that there are at least some of us opposed to this bike-shed color change.

@qrush
Member
qrush commented Mar 20, 2014

FWIW I have never seen interpolation inside of Gemfiles in any of my projects I've been involved in, for gem names or versions.

We have bigger problems to solve here. Our infrastructure still needs help. We're woefully behind on both issues and support requests. The list goes on and on. One quick merge and deploy to try out something different shouldn't be a big deal.

Let's try this out and see if we get other complaints of it or see any issues from it. If it causes a big deal, we can just simply go back.

@sferik
Member
sferik commented Mar 20, 2014

@joshsusser Just to clarify, the argument for this change was made by @garysweaver, not me. I don’t have a strong opinion about quotes and deferred to @qrush’s judgment, in this case.

@joshsusser

Oops, sorry for the misattribution!

@dblandin

👍

@leereilly

Happy to see this. I requested something similar via #468. Thanks @garysweaver 💓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment