Loading ...
Sorry, an error occurred while loading the content.

Re: [jslint] Mixed single and double quotes

Expand Messages
  • douglascrockford
    ... You should be glad to know that what you find annoying is not a consideration. I am concerned instead with correctness and readability.
    Message 1 of 6 , Jul 1, 2012
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, John Hawkinson <jhawk@...> wrote:

      > When you deal with strings that contain double quotes and strings
      > 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.
    • sandyhead25
      ... 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
      Message 2 of 6 , Jul 2, 2012
      • 0 Attachment
        > 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

        Austin
      • benquarmby
        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?
        Message 3 of 6 , Jul 3, 2012
        • 0 Attachment
          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 jslint_com@yahoogroups.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.
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.