After use Crystal since two years ago, Still not used to not having single quote strings.
Especially when you copy string from others modern language, like Ruby, BASH, which is really troublesome.
Sure we can use percent string literals, but I thought It’s more about personal style, i always prefer to use “” or ‘’ unless there is a string includes both single quote and double quote.
I think most Crystal users in the future will come from other modern languages, not C, which uses single quotes as Char.
As said by matz(the author of Ruby programming), the principle of least surprise is always desirable
No one(new user) wants to be taught to use double quotation for just puts a hello world.
icr:1> puts 'hello world'
syntax error in :1
Error: unterminated char literal, use double quotes for strings
It’s a bad first impression (at least when i use Crystal first time)
so, i consider we should create a new RFC to talk on this?
At first, it annoyed me, as I’m used to using ’ per default.
But having seen the amount of energy that’s been invested in the selection/fixing/discussion of either, in other languages, I’m pretty happy there’s only one choice in Crystal.
“Ah, you have to use single quotes because of performance… Ah, but if you decide you want to add an interpolation to your string, you have to change the quotes…”
It still bites me once in a while, and do like that ’ is an unshifted key, but it’s a sacrifice I’m willing to make (to quote Lord Farquaad).
I think there have been enough expressions from members of the community, among them many Core Team members.
Invalidating char literals is a huge cost and it’s not even offset by any hard benefits, except introducing another syntax to do something that’s already possible (which may even be considered a non-goal).
So I don’t see this is going to happen. Certainly not in any forseeable future.
That principle of least surprise depends on the language you’re coming from.
In fact, while the vast majority of languages use double quotes for string literals, regardless of their support for single quoted strings, a non negligible number of languages use single quotes to denote chars: C, Go, Java, Rust, Crystal, …
Realizing that, I changed my habit, and I now always using double quotes for strings, whatever the language. That solved everything.
I actually always thought that the differences between single quoted strings and double quoted strings in languages like Ruby and Python were counterintuitive and violated the principle of least surprise in some way - but maybe that’s just my BASIC/C++ background.
Well, nice if you can, but might not be an option due to coding style guides.
The most pathological example is mandating single because of performance, unless the string contains a single quote, in which case you have to use double. Not because you can’t escape it, but because the translation guide mandates double quotes for strings with single quotes as the translation tools copies it verbatim, and it might trip up the translators…
Not to mention that having both throws you a curveball when you want to search for a particular string usage.
I have not paid much attention to this difference.
However, I don’t like so much the fact that there are more characters that have to be escaped in a double-quote string than in a single-quote string. (Though % literals are provided for this purpose.)
The single quoted strings in Ruby are one of the more annoying aspects of it IMO, and I really like that Crystal didn’t carry that over from Ruby. When I write Ruby code (which is rare for me - mostly Rakefiles), I just use double-quotes or the %{ style everywhere since, in my mind, a single quote is for characters, double is for strings.
The only other languages I’ve encountered where single quotes can be used for strings are shell scripts and Pascal (and they annoy me in Pascal for the same reasons, too lol).
Based on my background, i wrote a lot of Ruby and BASH shell scripts, although i used to using double quotes under Crystal, based on personal habits, I rarely use %q or % (i consider it ugly), , I’d rather use a plain string or HEREDOC(both work on BASH shell too), it is kind of annoying occasionally because could not use single quotes write strings.
Depends on which variant of Pascal such as Oxygene (CLI-based language) which uses double quotes especially with string interpolation, but supports single quotes for string literals. Another interesting language, Haxe, uses double quotes as well, but interestingly enough, converts to single quotes when using string interpolation which is the opposite of most other languages (that support both single and double quotes for string literals). So one has to escape apostrophe’s if used as in:
trace('Gary\'s GPA is $gpa');
There are certainly some interesting choices being made by language designers.