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

Re: [jslint] else

Expand Messages
  • Douglas Crockford
    This isn t Perl. JavaScript has a dangerous semicolon insertion mechanism. More rigor is demanded.
    Message 1 of 3 , Mar 20 9:19 AM
    • 0 Attachment
      This isn't Perl. JavaScript has a dangerous semicolon insertion mechanism. More
      rigor is demanded.

      Jacob Davenport wrote:
      > In the world of Perl, we have this great book called Perl Best
      > Practices, and there Conway argues that "else" should be written like
      > this:
      >
      > if (ping == pong) {
      > dostuff();
      > }
      > else {
      > otherstuff();
      > }
      >
      > So, I do the same in JavaScript, avoiding putting else on the same
      > line as the unbrace. jslint doesn't seem to mind this formatting when
      > checking for white space.
      >
      > Views?
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
    • Jacob Davenport
      ... It certainly isn t Perl. I d argue it s much easier to write bad code in Perl than JavaScript, but at least it doesn t insert semicolons for you. You ve
      Message 2 of 3 , Mar 20 10:22 AM
      • 0 Attachment
        --- Douglas Crockford wrote:
        > This isn't Perl. JavaScript has a dangerous semicolon
        > insertion mechanism. More rigor is demanded.

        It certainly isn't Perl. I'd argue it's much easier to write bad code
        in Perl than JavaScript, but at least it doesn't insert semicolons for
        you. You've made that point many times.

        Do any browsers actually insert a semicolon after an unbrace carriage
        return? I don't think I'm being unsafe with breaking the unbrace and
        else statements with a carriage return. Doing so has the advantage
        that the "else" is lined up with the "if" statement, makes the code
        more readable, and the blocks more defined.

        If unbrace-return-else is actually dangerous, about which I'd like you
        to convince me, perhaps we can change jslint to catch it. If it's not
        dangerous, there's no need to change anything.
      Your message has been successfully submitted and would be delivered to recipients shortly.