Always Use Double-quoted Strings in Ruby
If you’re nerdy about what quote style you use (single or double), especially in Ruby, give this a read and tell me what you think.
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
If you’re nerdy about what quote style you use (single or double), especially in Ruby, give this a read and tell me what you think.
Comments
If you want us to tell you what we think, it would be easier for us to do that if you would enable comments directly on your blog. :-)
That said: the dubious speed gain of using single quotes is not at all worth the hassle and time of retrofitting when you have to interpolate or use an apostrophe.
It’s easier to type single quotes - one keypress.
Said this on Twitter, will say it here: the Ruby style guide only says you should be consistent, not that you should use one or the other. Rubocop and other tools force consistency by making you use one that it can check for when you need to switch (you’re using interpolation). There is absolutely nothing wrong with either approach as long as your code base is consistent.
@dave shudder The last thing I want on my blog is comments :) If I added them it would be with echochamber.js :)
@anton I don’t think optimizing for keypresses is worth it. For one the difference in speed is incredibly small. Most programmers are fast typers, and fast typers are going to barely see any difference. And two, as a programmer, the limiting factor is rarely how fast you can type. I spend far more time thinking about programming than actually typing. Rather, I spend more time thinking about programming so I can spend less time typing. It’s better to optimize for whatever allows you to make less decisions. Always using double quotes is one less decision you now have to make.
Post a comment