Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the character literal syntax "?" #631

Closed
lucasferronato opened this issue Feb 8, 2017 · 5 comments
Closed

Allow the character literal syntax "?" #631

lucasferronato opened this issue Feb 8, 2017 · 5 comments

Comments

@lucasferronato
Copy link

The guide is discouraging the use of literals syntax ?x but I think they should be used for single and double quotes, it seems clearer to me.

str.gsub(?',?"))
str.gsub("'", '"')

which one is better?

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 9, 2017

That's pretty debatable - e.g. that's not really a character literal syntax since Ruby 1.9. It's just another way to write a single-character string, so I'd rather use a string instead of confusing people with an odd special syntax that has lost its original purpose.

@bbatsov
Copy link
Collaborator

bbatsov commented Feb 9, 2017

Another point - gsub does string (or regexp) substitution anyways, so it's strange to see something that doesn't look like a string passed to it.

@scudelletti
Copy link

IMHO ?x is hard to google therefore hard for people that don't know what it does. And this syntax is even rare among old rubists.

I'm not a fan of rules exceptions because if there is too much it is hard to remember.
So for me it's easier to remember to avoid using ?a instead of using it in just one specific case.

Just my opinion though.

@lucasferronato
Copy link
Author

lucasferronato commented Feb 10, 2017

That's pretty debatable

It was my intention opening this issue.

e.g. that's not really a character literal syntax since Ruby 1.9. It's just another way to write a single-character string

I used "character literal syntax" because this is how the guide calls it.

so I'd rather use a string instead of confusing people with an odd special syntax that has lost its original purpose.

I think it's only odd because it's not used at all but just open your rails console and run ?' and you'll understand what it does.

Another point - gsub does string (or regexp) substitution anyways, so it's strange to see something that doesn't look like a string passed to it.

Again, it is strange because we don't use it, for me, when I began learning ruby it was weird to use %() for interpolated and double quoted strings but now it's not.

IMHO ?x is hard to google therefore hard for people that don't know what it does. And this syntax is even rare among old rubists.

Just googled ruby question mark string the first result explains exactly what the operators do but if you remove "string" from the whatever search term with "ruby question mark" in it it's in fact hard to find it :(

I'm not a fan of rules exceptions because if there is too much it is hard to remember.
So for me it's easier to remember to avoid using ?a instead of using it in just one specific case.

I don't meant to force people using ? and stop using quotes but instead allow using ? too when the single character string is a quote, that way you'll not be forced to remember this exception but I'm pretty sure people will remember anyways.

@bbatsov @scudelletti Sorry if I sounded rude at some point but english is not my native language, I just meant to show you my opinion :)

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 12, 2019

No worries. My biggest concern with it is that it's a legacy remnant from Ruby 1.8 and until very recently it was very likely that it was going to be removed in Ruby 3.0 (and it is still probably going to be removed later). That's why I think we can't really encourage people to use it, knowing that a few years down the road it might cause breakage to their code.

@bbatsov bbatsov closed this as completed Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants