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

Re: [jslint] Re: Formatting question

Expand Messages
  • Mark Volkmann
    Keep in mind this option: var elementInWebPage, i, j; elementInWebPage = YAHOO.util.Dom.get( someElementID ); I like to declare all the local variables at the
    Message 1 of 16 , Aug 4, 2011
    • 0 Attachment
      Keep in mind this option:

      var elementInWebPage, i, j;

      elementInWebPage = YAHOO.util.Dom.get('someElementID');

      I like to declare all the local variables at the beginning of each function
      in alphabetical order and then initialize them on separate lines.
      The only time I initialized them in the var statement is when they have
      short values like 1, [], or {}.

      --
      R. Mark Volkmann
      Object Computing, Inc.


      [Non-text portions of this message have been removed]
    • g2223060
      I agree with you, Mark- I have been using that style in my own code. Probably why I haven t seen this error until the developer asked for my help with it :)
      Message 2 of 16 , Aug 4, 2011
      • 0 Attachment
        I agree with you, Mark- I have been using that style in my own code. Probably why I haven't seen this error until the developer asked for my help with it :) Maybe we should just have a policy that you don't initialize in the declaration...

        Some experimentation with JSLint shows that this is only enforced when there is ONE variable on the first line. For example, this passes:

        var a, b,
        c, d, e, f, g, h, i;

        But this does not:

        var x,
        y, z;

        -Steve

        --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
        >
        > Keep in mind this option:
        >
        > var elementInWebPage, i, j;
        >
        > elementInWebPage = YAHOO.util.Dom.get('someElementID');
        >
        > I like to declare all the local variables at the beginning of each function
        > in alphabetical order and then initialize them on separate lines.
        > The only time I initialized them in the var statement is when they have
        > short values like 1, [], or {}.
        >
        > --
        > R. Mark Volkmann
        > Object Computing, Inc.
        >
        >
        > [Non-text portions of this message have been removed]
        >
      • abyssoft@ymail.com
        I use a formatting that is indeed supported by JSLint and is highly readable to me var ....varname1, ....varname2 = suchandsuch , ....varname3 = 1234; that
        Message 3 of 16 , Aug 4, 2011
        • 0 Attachment
          I use a formatting that is indeed supported by JSLint and is highly readable to me

          var
          ....varname1,
          ....varname2 = "suchandsuch",
          ....varname3 = 1234;

          that way if I see a var I know that until I see the ; I am still with in my declaration block.


          --- In jslint_com@yahoogroups.com, Doc Emmett Splendid <emmett.thesane@...> wrote:
          >
          > I've struggled with how to organize unintialised variables in one full var statement as well (largely because I only recently became convinced through experience that the "one var per function" is The Right Thing To Do). I haven't followed this format in the past, but I will do so henceforth for the very reason you say.
          >
          > Emmett
          >
          >
          > ________________________________
          > From: Robert Ferney <capnregex@...>
          > To: jslint_com@yahoogroups.com
          > Sent: Thursday, 4 August 2011, 13:33
          > Subject: Re: [jslint] Re: Formatting question
          >
          >
          >  
          > Just as a personal impression.
          > I do find
          >
          > var i, j,
          > elementInWebPage = YAHOO.util.Dom.get('someElementID');
          >
          > more readable than
          >
          > var elementInWebPage = YAHOO.util.Dom.get('someElementID'),
          > i, j;
          >
          > having the un-initialize variables first, makes if obvious that they are
          > being declared as variables. while in the second form, the i, j; look a bit
          > orphaned.
          >
          > - Robert Ferney
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >
          >
          > [Non-text portions of this message have been removed]
          >
        • abyssoft@ymail.com
          That looks like jslint is right when you review it. by setting a single variable on the line of the var statement you are setting the expected pattern of 1
          Message 4 of 16 , Aug 4, 2011
          • 0 Attachment
            That looks like jslint is right when you review it.

            by setting a single variable on the line of the var statement you are setting the expected pattern of 1 variable per line

            by setting either 2+ variables or no variables on the line of the var statement you are setting the expected pattern of one or more per line following the var statement.

            I mention in another reply in this thread that I use the

            var
            ....varname1,
            ....varname2 = "string",
            ....varname3 = 0;

            pattern with one variable per line and var statement on it's own line, as it is both supported by JSLint and I find it very easy to read.


            --- In jslint_com@yahoogroups.com, "g2223060" <g2223060@...> wrote:
            >
            > I agree with you, Mark- I have been using that style in my own code. Probably why I haven't seen this error until the developer asked for my help with it :) Maybe we should just have a policy that you don't initialize in the declaration...
            >
            > Some experimentation with JSLint shows that this is only enforced when there is ONE variable on the first line. For example, this passes:
            >
            > var a, b,
            > c, d, e, f, g, h, i;
            >
            > But this does not:
            >
            > var x,
            > y, z;
            >
            > -Steve
            >
            > --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@> wrote:
            > >
            > > Keep in mind this option:
            > >
            > > var elementInWebPage, i, j;
            > >
            > > elementInWebPage = YAHOO.util.Dom.get('someElementID');
            > >
            > > I like to declare all the local variables at the beginning of each function
            > > in alphabetical order and then initialize them on separate lines.
            > > The only time I initialized them in the var statement is when they have
            > > short values like 1, [], or {}.
            > >
            > > --
            > > R. Mark Volkmann
            > > Object Computing, Inc.
            > >
            > >
            > > [Non-text portions of this message have been removed]
            > >
            >
          • Tom Worster
            ... If you take that step, I hope you do so because you believe it is a good policy, not because of a tool like JSLint. Personally, fwiw, I think initializing
            Message 5 of 16 , Aug 5, 2011
            • 0 Attachment
              On 8/4/11 5:40 PM, "g2223060" <g2223060@...> wrote:

              >I agree with you, Mark- I have been using that style in my own code.
              >Probably why I haven't seen this error until the developer asked for my
              >help with it :) Maybe we should just have a policy that you don't
              >initialize in the declaration...

              If you take that step, I hope you do so because you believe it is a good
              policy, not because of a tool like JSLint.

              Personally, fwiw, I think initializing to a literal in the declaration is
              just fine, and separating var status = 'ready'; into two statements
              doesn't help, but calling functions and doing calculations etc. is for
              subsequent lines of code.

              tom
            • R. Mark Volkmann
              One reason I like that style, declaring all local variables on one line and initializing them later, is that it reminds me of Smalltalk. ... R. Mark Volkmann
              Message 6 of 16 , Aug 5, 2011
              • 0 Attachment
                One reason I like that style, declaring all local variables on one line and initializing them later, is that it reminds me of Smalltalk.

                ---
                R. Mark Volkmann
                Object Computing, Inc.

                On Aug 5, 2011, at 7:24 AM, Tom Worster <fsb@...> wrote:

                > On 8/4/11 5:40 PM, "g2223060" <g2223060@...> wrote:
                >
                > >I agree with you, Mark- I have been using that style in my own code.
                > >Probably why I haven't seen this error until the developer asked for my
                > >help with it :) Maybe we should just have a policy that you don't
                > >initialize in the declaration...
                >
                > If you take that step, I hope you do so because you believe it is a good
                > policy, not because of a tool like JSLint.
                >
                > Personally, fwiw, I think initializing to a literal in the declaration is
                > just fine, and separating var status = 'ready'; into two statements
                > doesn't help, but calling functions and doing calculations etc. is for
                > subsequent lines of code.
                >
                > tom
                >
                >


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