[ckan-dev] Single vs double quotes

Sean Hammond sean.hammond at okfn.org
Mon Nov 19 12:41:02 UTC 2012


I know it's a pain to change something like this as all the existing
code would be inconsistent, but our code is already inconsistent on
this point and I wonder if it's worth changing our coding standards
rather than continuing as we are.

Can we stop it with this single quotes thing?

I don't know why we use single quotes in CKAN but the only reason I've
heard for this is that people think ' looks less "noisy" than ", but:

1  Any natural language string such as any message to the user is likely
   to contain apostrophes in the string itself which have to be escaped
   in an ugly and error-prone way: 'You\'ve got an error!'

2  Here it's ridiculous not to do "You've got an error!" instead

3  Even if your natural language string happens not to contain any apostrophes
   now, you might add one when you edit it later and then forget to
   escape it, so you better put the string in double-quotes anyway to be
   safe

4  If we're putting natural language strings in double-quotes we may as
   well put 'my-identifier' type strings in double-quotes as well
   because otherwise it's inconsistent and confusing

5  The same goes for docstrings

6  Both PEP8 and PEP257 have all the strings in their examples in double
   quotes (PEP257 actually says to put all docstrings in triple double
   quotes)

7  If we just used double quotes we could delete the two different parts of
   our coding standards where we have to tell people to deviate from
   PEP8 and PEP257 respectively by using single quotes

8  Right now our coding standards say we use single-quotes which is a lie
   because we have loads of double-quotes in there because of 1

9  To make the coding standards true we would have to say something ridiculous
   like:

    Use the single-quote character ' rather than the double-quote
    character " for string literals, e.g. 'my_string'. Except when the
    string contains natural language that is likely to contain
    apostrophes that would need to be escaped in an ugly and
    error-prone way. Then it’s better to just use double-quotes, e.g.
    "You're allowed to do this".

   Or we say single quotes everywhere and escape apostrophes which is
   equally silly.

Sorry I know it's nit-picky but I was going over the coding standards
looking for unnecessary things that could be removed to make them
shorter and this one was grating at me.




More information about the ckan-dev mailing list