Re: [jslint] Mixed single and double quotes
- --- In firstname.lastname@example.org, John Hawkinson <jhawk@...> wrote:
> When you deal with strings that contain double quotes and stringsYou should be glad to know that what you find annoying is not a consideration. I am concerned instead with correctness and readability.
> that contain single quotes:
> "Warning: can't find token."
> 'Invalid input: "cheese"'
> it is convenient to switch between single and double quotes.
> A rule that prevented that would be annoying.
> You should be glad to know that what you find annoying is not a consideration. I am concerned instead with correctness and readability.Mixing of quotes can be a maintainability issue. In my own application I have all of my logic divided into libraries that are directly supplied to a parent container function representing the entirety of the application. Many of these library components I have forked from other authors. Some have used single quotes and other used double quotes. If the logic in each library never moves out of the library you are fine, but if you want to transplant one condition to another library item you could run into trouble.
With regards to Hawkinson's comment about nested quotes I come up with a tedious solution in my own app. I have chosen to use double quotes for everything where a quote is required in the JS syntax. If there exists a string already containing a double quote character as part of the string literal I escape it instead of shying away from consistency.
var example = "what I am doing with \" characters";
As long as you are using an editor that performs syntax coloring there is no harm to readability. Otherwise you actually have to read that there is a forward slash before the quote character and the string continues. I have not found this to be a problem
- That sounds like good advice. Like you say though, difficult to verify. Would you analyze the contents of the string, or the subject of the assignment? Something else?
Without a reliable way to verify the intention of a string, applying the same advice you give for tabs vs. spaces seems preferable - Pick one and use it consistently.
That advice would also prevent cowboy developers from creatively misinterpreting the difference between internal and external.
--- In email@example.com, "douglascrockford" <douglas@...> wrote:
> My advice is to use "double quotes" for strings that are meaningful externally, like urls, html templates, and error messages; and to use 'single quotes' for strings that are meaningful internally, like character constants, property names, and symbols.
> I have not discover an automatic way to verify usage.