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

Re: [jslint] Re: one line if statements

Expand Messages
  • Michael S. Mikowski
    Hi Mark: ... I agree. That s a cure almost worse than the disease. So I do turn off strict white space, as implied in an unrelated jslint response I just
    Message 1 of 9 , Sep 14, 2010
    • 0 Attachment
      Hi Mark:

      On Monday, August 23, 2010 07:27:35 pm you wrote:
      > If I understand correctly, in order to get your code to pass JSLint, you
      > have to turn off strict whitespace checking.
      > If you do that then the following will also be allowed (I hope the extra
      > whitespace in my code sample gets retained in the email):
      > if (a < 0)
      > {
      > return -1;
      > }
      >
      > I don't want that to be allowed. I want a single-line if statement to be
      > treated as an exception to the strict whitespace rule.

      I agree. That's a cure almost worse than the disease. So I do turn off strict
      white space, as implied in an unrelated jslint response I just posted.

      > What do you mean by "syntactically correct". My suggested code is
      > syntactically correct, just not JSLint correct.

      I had assumed the single-line form is deprecated; one finds no mention of it
      in the w3schools guide: http://www.w3schools.com/js/js_if_else.asp. But I'm
      willing to admit that might not be the case.

      My solution is to turn off white space checking in jslint (which is highly
      subjective anyway), and use the single line form as presented below.

      As always, YMMV.

      Cheers, Mike


      > On Mon, Aug 23, 2010 at 5:57 PM, Michael Mikowski
      <z_mikowski@...>wrote:
      > > Hi Mark:
      > > And what is wrong with the following?
      > >
      > > ------------
      > >
      > > function foo(a, b) {
      > > if (a < 0){ return -1;}
      > > if (a*2 > b){ return 1;}
      > >
      > > // Now have several lines of code (say less than 10) that do something
      > > // complicated with a and b and set the local variable "result".
      > >
      > > return result;
      > > }
      > > ---------------
      > >
      > > It provides all the benefits you mentioned, with the benefit of being
      > > syntatically correct.
      > >
      > > Cheers, Mike
      > >
      > >
      > > ----- Forwarded Message ----
      > > From: Mark Volkmann
      > > <r.mark.volkmann@...<r.mark.volkmann%40gmail.com>
      > >
      > > To: jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>
      > > Sent: Mon, August 23, 2010 1:10:57 PM
      > > Subject: Re: [jslint] Re: one line if statements
      > >
      > > The benefit I see is conciseness of functions without loss of
      > > readability. It is fairly common for me to write functions that test
      > > parameters and make a determination about whether the rest of the code
      > > needs to be executed or whether the result is already known. Here's a
      > > simple, contrived example:
      > >
      > > function foo(a, b) {
      > > if (a < 0) return -1;
      > > if (a*2 > b) return 1;
      > >
      > > // Now have several lines of code (say less than 10) that do something
      > > // complicated with a and b and set the local variable "result".
      > >
      > > return result;
      > > }
      > >
      > > This is visually appealing to me. It makes it easy to take in the entire
      > > function at a glance and doesn't require scrolling in an editor to see
      > > all the code.
      > >
      > > --
      > > R. Mark Volkmann
      > > Object Computing, Inc.
      > >
      > > [Non-text portions of this message have been removed]
      > >
      > > [Non-text portions of this message have been removed]


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.