We should add a sniff to check for double quote usage when the string doesn't contain a variable. The coding standards recommend using single quotes unless double quotes are absolutely necessary.

Comments

klausi’s picture

From https://drupal.org/coding-standards#quotes

Drupal does not have a hard standard for the use of single quotes vs. double quotes. Where possible, keep consistency within each module, and respect the personal style of other developers.

So not sure if Coder should throw a warning or not.

psynaptic’s picture

Status: Active » Closed (won't fix)

I guess I have misinterpreted the recommendation as a requirement:

With that caveat in mind: single quote strings are known to be faster because the parser doesn't have to look for in-line variables. Their use is recommended except in two cases:

In-line variable usage, e.g. "<h2>$header</h2>".
Translated strings where one can avoid escaping single quotes by enclosing the string in double quotes. One such string would be "He's a good person." It would be 'He\'s a good person.' with single quotes. Such escaping may not be handled properly by .pot file generators for text translation, and it's also somewhat awkward to read.

For a long time, I've been fully in the mind that double quotes should be avoided unless single quotes are necessary but I'm rethinking that now and I think the use of double quotes everywhere makes a lot more sense. It feels wrong to switch from single to double just for the cases where they are needed. Consistency is important in code and it would work consistently to just use double quotes everywhere.

I don't buy the performance argument but someone mentioned to me just a moment ago that they think double quotes slightly are harder to read.

I'm going to close this and change my personal style to use double quotes but allow people to use whatever they want in code reviews.