5 ms·
> Single-quotes are great for indicating "there is no interpolation here" and for strings that embed double-quotes. I used to think that too. But it doesn’t re
by ekzy 6y ago
> Single-quotes are great for indicating "there is no interpolation here" and for strings that embed double-quotes.
I used to think that too. But it doesn’t really help that much, because interpolation is fairly obvious with syntax highlighting. I changed my mind and I prefer consistency, and have every string the same. Also, if you need to add or remove interpolation then you don’t have to change the type of quotes.
- mpd 6y agoRubocop can autocorrect strings to use the "correct" quotes based on context. The rule for "Standard" is silly and unnecessary. The argument about readability falls flat with me. At the end of the day, let the tools enforce this nonsense, but I'm still a performance wonk at some level and it drives me crazy seeing interpolatable strings without interpolations.
- anamexis 6y agoThere is zero performance difference between single quoted strings and double quoted strings with no interpolation.
- fomine3 6y agoTheoretically parsing "" should have very little overhead only on parsing, but parsing string is tiny work so it can't be problem. Anyway who cares such performance won't use Ruby.
- Lio 6y agoThat's interesting. I was told about a ruby project years ago where they gained a measurable performance boost by converting all the strings without interpolation to single quotes. That's a vague anecdote so should be taken with a pinch of salt. Even if it was once the case VM often improve to fix these edge cases. So I was just wondering if there was anything more formal to prove this so that I can avoid this preconception I've been carrying around for years based on nothing more than someone's now dated Lightning Talk.
- anamexis 6y agoHere's a good summary by someone on StackOverflow, with links to Ruby source: https://stackoverflow.com/a/1836838/2850811 https://stackoverflow.com/a/1836838/2850811
- Lio 6y agoThanks for the reply. It seems that any cost is small and at parse time rather than runtime. That seems like a good enough reason to always use double " for consistency to me.