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

else

Expand Messages
  • Jacob Davenport
    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) {
    Message 1 of 3 , Mar 20, 2008
    View Source
    • 0 Attachment
      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?
    • Douglas Crockford
      This isn t Perl. JavaScript has a dangerous semicolon insertion mechanism. More rigor is demanded.
      Message 2 of 3 , Mar 20, 2008
      View Source
      • 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 3 of 3 , Mar 20, 2008
        View Source
        • 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.