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

Single quotes (') or double quotes (") #4

Closed
lukpueh opened this issue Oct 26, 2016 · 7 comments · Fixed by #21
Closed

Single quotes (') or double quotes (") #4

lukpueh opened this issue Oct 26, 2016 · 7 comments · Fixed by #21

Comments

@lukpueh
Copy link
Member

lukpueh commented Oct 26, 2016

In Python single quotes (') and double quotes can be used (") interchangeably to designate strings. While our code-style-guidelines suggest to use triple-double-quotes (""") for docstrings, we don't have a policy for normal strings.

Please participate in this discussion to help us promote quote consistency in our projects!

I'd like to start the discussion with the following suggestion:

  • Use single quotes everywhere , unless
  • the string contains single quotes, then use double quotes.
"""What the foo? """
foo = 'bar'
baz = {'foo': foo}
if baz['foo'] == 'bar':
  print("foo's value is 'bar'")
@vladimir-v-diaz
Copy link
Contributor

I prefer to use only double quotes for the triple-double-quotes of docstrings and single quotes everywhere else, but wouldn't mind your proposed exception.

What if for some reason the string must contain double quotes?
"foo's value is "bar""

Do we escape it in this case? I do understand that you'd like to avoid escape sequences in strings.

@lukpueh
Copy link
Member Author

lukpueh commented Oct 26, 2016

Valid point. While only double quotes in a single quoted string aren't a problem with above strategy

print('foo has the value "bar"')

mixing them would be.
I'd maybe encourage to avoid mixing double quotes and single quotes in a string.
And if it is absolutely necessary we could stick to the single-quote-preference and escape like so:

print('foo\'s value is "bar"')

@aaaaalbert
Copy link
Contributor

I prefer double quotes (solo and triple) everywhere. I use them in handwriting, I use them in other languages if allowed.

It's 90% muscle memory, so I could re-learn and use single quotes just as well, but 10% useful for what I think is still a common case: communicating with the user in plain English.

Following your proposal, 'I\'m sorry Dave, I\'m afraid I can\'t do that' should obviously use double quotes, not escapes. My point is that I think that this happens frequently enough that the exception from the single-quote default would either become the default, or cause still lots of visual inconsistency (according to or accidentally ignoring the rules) throughout our code. This is only an epsilon better than the mix of quote styles we have at the moment.

@aaaaalbert
Copy link
Contributor

Two random data points to fuel the flame war:

  • I hope we agree to not consider this style: 'English': "There are %(number_of_lights)s lights."
  • For people with a C background, double quotes perhaps look more string-y.

@lukpueh
Copy link
Member Author

lukpueh commented Oct 27, 2016

I must admit that I loosely have been using the style that you'd rather not consider. Single words are almost like single characters whereas phrases..., right? :)

Anyway, I'm fine with Albert's proposal too (double quotes everywhere), as long as we have some policy.

@awwad
Copy link
Contributor

awwad commented Oct 27, 2016

For whatever reason, I’ve been using single quotes essentially everywhere (unless they’re in the string, in which case I either escape or use double quotes). I think Vlad and I more or less have the same approach.

I, too, don’t mind changing, if it’s in the name of a consistent lab style, whether it’s almost always single or almost always double.

On Oct 27, 2016, at 15:30, lukpueh [email protected] wrote:

I must admit that I loosely have been using the style that you'd rather not consider. Single words are almost like single characters whereas phrases..., right? :)

Anyway, I'm fine with Albert's proposal too (double quotes everywhere), as long as we have some policy.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #4 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AMpkOOXsHzDX3c_aPjR8WDg6NwClmM_kks5q4PvRgaJpZM4Khl-V.

@lukpueh
Copy link
Member Author

lukpueh commented Nov 18, 2020

Starting with #21 we mandate Google Style Guide and recommend PEP8, both of which only recommend to pick one quote-style and stick with it, unless it requires a lot of escapes in a given string, then it's okay to use the other.

I think we should state a clear preference for either of them in the String section of the new style guide added in #21. FWIW, in the examples of that new guide I consistently use double quotes ", but it would be easy to switch, if there is a consensus for single '.

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

Successfully merging a pull request may close this issue.

4 participants