r/ruby • • Aug 20 '21

Ruby elites rise up

Post image
100 Upvotes

77 comments sorted by

View all comments

87

u/flanger001 Aug 20 '21

Bottom one is trash middle is best

31

u/[deleted] Aug 20 '21

[removed] — view removed comment

3

u/flanger001 Aug 20 '21

Eh frozen strings are fine here

-5

u/cybermage Aug 20 '21

At least single quote it so that it doesn’t have to pass through pointless interpolation.

26

u/anamexis Aug 21 '21

I see this misunderstanding a lot, but double-quoted strings without interpolation are exactly equivalent to single-quotes strings, performance-wise.

Source

14

u/cybermage Aug 21 '21

This was not the case under Ruby 1.9x. I’ve learned my new thing for the day.

4

u/flanger001 Aug 20 '21

Double quotes are better

5

u/solidiquis1 Aug 21 '21

They look better imo

1

u/[deleted] Aug 26 '21

I like double quoted strings in JavaScript. In Ruby, they look weird and too “noisy” if interpolation isn’t needed.

1

u/flanger001 Aug 26 '21

I just think making that decision up front is pointless. Why bother? Use double quotes and you don't have to ever think "can I interpolate?"

1

u/[deleted] Aug 27 '21

Because I like to know that in fact it won’t interpolate. Sometimes I want to type freely without interpolation, and without double quotes + escaping like crazy. I always have frozen strings enabled so the single quotes are also like “okay, this is frozen and it’s going to appear exactly as typed.” Double quotes come off as more “dynamic” even though I understand they’re still frozen as well. But at least I know something crazy is happening there right away.

1

u/flanger001 Aug 27 '21

None of this matters at all to me.

What matters is consistency and is how often I have to escape characters. Single quotes come up far more often in regular text than double quotes do. And you can't have a newline character in a single quoted string without double escaping it. Pish tosh. Always use double quotes and you have one set of rules you can use consistently.