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

Re: Spacing Bug

Expand Messages
  • Douglas Crockford
    ... I recommend that you take JSLint s advice.
    Message 1 of 6 , Jan 24, 2011
    View Source
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
      >
      > /* Given */
      > /*jslint strict: true, white: true, browser: true, devel: true, windows: true, sub: true, undef: true */
      > /*jslint nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, immed: true */
      > /*jslint maxerr: 50, indent: 4 */
      > /**/ //used to represent 4 spaces
      >
      > var projectItemsIds = {};
      > var nlapiGetLineItemValue;
      > var currentItemIndex;
      >
      > if (
      > /**/projectItemsIds.hasValue(
      > /**//**/nlapiGetLineItemValue(
      > /**//**//**/'item',
      > /**//**//**/'item',
      > /**//**//**/currentItemIndex
      > /**//**/)
      > /**/) &&
      > /**/parseFloat(
      > /**//**/nlapiGetLineItemValue(
      > /**//**//**/'item',
      > /**//**//**/'quantity',
      > /**//**//**/currentItemIndex
      > /**//**/)
      > /**/) > 0
      > ) {
      > /**///dosomething
      > /**/var someVar = true;
      > }
      >
      > results in
      >
      > Error:
      > Problem at line 18 character 5: Expected 'parseFloat' at column 9, not column 5.
      >
      > /**/parseFloat(
      >
      > column 5 is the correct column

      I recommend that you take JSLint's advice.
    • abyssoft@ymail.com
      Ok my question then is how would if (     projectItemsIds.hasValue(          123     ) &&         parseFloat(          2
      Message 2 of 6 , Jan 24, 2011
      View Source
      • 0 Attachment
        Ok my question then is how would

        if (
            projectItemsIds.hasValue(
                '123'
            ) &&
                parseFloat(
                "2"
            ) > 0 ||
                parseFloat(
                "-2"
            ) < 0
        ) {

        where the 2nd and subsequent elements of the same level of logic is indented and offset from the alignment of the 1st element, be more readable then

        if (
            projectItemsIds.hasValue(
                '123'
            ) &&
            parseFloat(
                "2"
            ) > 0 ||
            parseFloat(
                "-2"
            ) < 0
        ) {

        where each element of the same level of logic is properly aligned?

        Given a rational I can adapt to the advice given.

        As always, Mr. Crockford, thank you for your time and expertise.



        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
        >
        > --- In jslint_com@yahoogroups.com, "abyssoft@" <abyssoft@> wrote:
        > >
        > > /* Given */
        > > /*jslint strict: true, white: true, browser: true, devel: true, windows: true, sub: true, undef: true */
        > > /*jslint nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, immed: true */
        > > /*jslint maxerr: 50, indent: 4 */
        > > /**/ //used to represent 4 spaces
        > >
        > > var projectItemsIds = {};
        > > var nlapiGetLineItemValue;
        > > var currentItemIndex;
        > >
        > > if (
        -- snip --
        > > results in
        > >
        > > Error:
        > > Problem at line 18 character 5: Expected 'parseFloat' at column 9, not column 5.
        > >
        > > /**/parseFloat(
        > >
        > > column 5 is the correct column
        >
        > I recommend that you take JSLint's advice.
        >
      • Erik Eckhardt
        How did you get those spaces to stay? :) Anyway, I think it wants the expression to follow one space after the operator, not be on the next line. But why would
        Message 3 of 6 , Jan 24, 2011
        View Source
        • 0 Attachment
          How did you get those spaces to stay? :)

          Anyway, I think it wants the expression to follow one space after the
          operator, not be on the next line.

          But why would you put the operator at the end of the line instead of at the
          beginning?

          if (
          ___projectItemsIds.hasValue('123')
          ______&& parseFloat("2") > 0
          ______|| parseFloat("-2") < 0
          ) {

          Though this seems to me to need parentheses to make precedence clearer.

          On Mon, Jan 24, 2011 at 2:07 PM, abyssoft@... <abyssoft@...>wrote:

          >
          >
          > Ok my question then is how would
          >
          > if (
          > projectItemsIds.hasValue(
          > '123'
          > ) &&
          > parseFloat(
          > "2"
          > ) > 0 ||
          > parseFloat(
          > "-2"
          > ) < 0
          > ) {
          >
          > where the 2nd and subsequent elements of the same level of logic is
          > indented and offset from the alignment of the 1st element, be more readable
          > then
          >
          > if (
          > projectItemsIds.hasValue(
          > '123'
          > ) &&
          > parseFloat(
          > "2"
          > ) > 0 ||
          > parseFloat(
          > "-2"
          > ) < 0
          > ) {
          >
          > where each element of the same level of logic is properly aligned?
          >
          > Given a rational I can adapt to the advice given.
          >
          > As always, Mr. Crockford, thank you for your time and expertise.
          >
          >
          > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Douglas
          > Crockford" <douglas@...> wrote:
          > >
          > > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>,
          > "abyssoft@" <abyssoft@> wrote:
          > > >
          > > > /* Given */
          > > > /*jslint strict: true, white: true, browser: true, devel: true,
          > windows: true, sub: true, undef: true */
          > > > /*jslint nomen: true, eqeqeq: true, plusplus: true, bitwise: true,
          > regexp: true, immed: true */
          > > > /*jslint maxerr: 50, indent: 4 */
          > > > /**/ //used to represent 4 spaces
          > > >
          > > > var projectItemsIds = {};
          > > > var nlapiGetLineItemValue;
          > > > var currentItemIndex;
          > > >
          > > > if (
          > -- snip --
          >
          > > > results in
          > > >
          > > > Error:
          > > > Problem at line 18 character 5: Expected 'parseFloat' at column 9, not
          > column 5.
          > > >
          > > > /**/parseFloat(
          > > >
          > > > column 5 is the correct column
          > >
          > > I recommend that you take JSLint's advice.
          > >
          >
          >
          >


          [Non-text portions of this message have been removed]
        • abyssoft@ymail.com
          ... mostly it a semantics thing for me, in that my eye flows best if each element is on the same indent versus the same bool operator. abc and def or ghi
          Message 4 of 6 , Jan 24, 2011
          View Source
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, Erik Eckhardt <erik@...> wrote:
            >
            > How did you get those spaces to stay? :)
            >
            > Anyway, I think it wants the expression to follow one space after the
            > operator, not be on the next line.
            >
            > But why would you put the operator at the end of the line instead of at the
            > beginning?
            >
            > if (
            > ___projectItemsIds.hasValue('123')
            > ______&& parseFloat("2") > 0
            > ______|| parseFloat("-2") < 0
            > ) {
            >
            > Though this seems to me to need parentheses to make precedence clearer.

            mostly it a semantics thing for me, in that my eye flows best if each element is on the same indent versus the same bool operator.

            abc and
            def or
            ghi

            versus

            abc
            and def
            or ghi

            and yes for the snippet above if it wasn't just a quick example that I threw in to test parenthesis would indeed be needed for clear precedence.
          • Douglas Crockford
            ... Since you asked, I would write it like this: if (projectItemsIds.hasValue( 123 ) && parseFloat( 2 ) 0 || ````````parseFloat( -2 )
            Message 5 of 6 , Jan 24, 2011
            View Source
            • 0 Attachment
              --- In jslint_com@yahoogroups.com, "abyssoft@..." <abyssoft@...> wrote:
              >
              > Ok my question then is how would
              >
              > if (
              >     projectItemsIds.hasValue(
              >         '123'
              >     ) &&
              >         parseFloat(
              >         "2"
              >     ) > 0 ||
              >         parseFloat(
              >         "-2"
              >     ) < 0
              > ) {
              >

              Since you asked, I would write it like this:


              if (projectItemsIds.hasValue('123') && parseFloat("2") > 0 ||
              ````````parseFloat("-2") < 0) {


              But I should point out that I am not paid by the line.

              In looking at your code, I see a possible error in depending on the precedence rules to make the interaction of && and || right. It is likely that JSLint will soon require more parentheses there.
            Your message has been successfully submitted and would be delivered to recipients shortly.