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

[jslint] Re: Can we please lose the trailing whitespace and "this" restriction?

Expand Messages
  • paulcrowder1979
    ... Writing the code is trivial. Pushing out an IDE plug-in to 100+ developers that will run the code when they save their files, waiting for the plug-in to
    Message 1 of 22 , Nov 17, 2011
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, Michael Mikowski <z_mikowski@...> wrote:
      >
      > Removing trailing whitespace IS trivial:
      >
      > sed -i -e 's/\s*$//' $(find ./ -type f)
      >
      >
      > Of course if you are using notepad, it might take a few months.
      >

      Writing the code is trivial. Pushing out an IDE plug-in to 100+ developers that will run the code when they save their files, waiting for the plug-in to propagate to every developer, then updating our check-in policy to enforce the new rule is not trivial. I don't mind going through that effort when the pay-off is significant, but removing trailing whitespace has zero impact on the shipping product so it's not worth the effort.

      It looks like my only recourse at this point is to rip out the two lines of JSLint that enforce the trailing whitespace rule and the "this" strict violation rule each time I upgrade JSLint. I actually have more of a problem with the "this" restriction for reasons I mentioned earlier, but I have no confidence that it will be addressed after having read the opinion of his users that Douglas Crockford stated in his previous post.
    • Michael Mikowski
      Hey Paul: I feel your pain.  I don t know your process, environment, and restrictions.  So all this is speculation. If you are supporting 100+ developers,
      Message 2 of 22 , Nov 17, 2011
      • 0 Attachment
        Hey Paul:

        I feel your pain.  I don't know your process, environment, and restrictions.  So all this is speculation.

        If you are supporting 100+ developers, you certainly seem to have the critical mass to justify creating a forked version for your purposes.  You could then distribute to the developers via your SCMS, and using it in your build process.  Our official JSLint utility is kept in SCMS, and changes about once per quarter.  It is almost always adjusted to meet our standards that deviate from the JSLint way.

        I am very happy with that solution, and am very greatfull that I don't have to write 99% of our Lint utility, and that Mr. Crockford is kind enough to share this wonderful software with us, even if his idea of well formatted code doesn't agree with mine :)

        Sincerely, Mike

        ps here is my vim "plugin" for removing whitespace:

        "=====[ ;removes trailing space ]=====

        map ;k :%s?\s\+$??<CR>
         
        pss

        If you wanted to enforce no-trailing-whitespace, you could update your entire repository as below, check-in, and then make developers aware that trailing whitespace will no longer be acceptable under JSLint.



        ________________________________
        From: paulcrowder1979 <paul@...>
        To: jslint_com@yahoogroups.com
        Sent: Thursday, November 17, 2011 7:31 AM
        Subject: [jslint] Re: Can we please lose the trailing whitespace and "this" restriction?


         


        --- In jslint_com@yahoogroups.com, Michael Mikowski <z_mikowski@...> wrote:
        >
        > Removing trailing whitespace IS trivial:
        >
        > sed -i -e 's/\s*$//' $(find ./ -type f)
        >
        >
        > Of course if you are using notepad, it might take a few months.
        >

        Writing the code is trivial. Pushing out an IDE plug-in to 100+ developers that will run the code when they save their files, waiting for the plug-in to propagate to every developer, then updating our check-in policy to enforce the new rule is not trivial. I don't mind going through that effort when the pay-off is significant, but removing trailing whitespace has zero impact on the shipping product so it's not worth the effort.

        It looks like my only recourse at this point is to rip out the two lines of JSLint that enforce the trailing whitespace rule and the "this" strict violation rule each time I upgrade JSLint. I actually have more of a problem with the "this" restriction for reasons I mentioned earlier, but I have no confidence that it will be addressed after having read the opinion of his users that Douglas Crockford stated in his previous post.




        [Non-text portions of this message have been removed]
      • Jean-Charles Meyrignac
        ... In my company, we use SVN+CCNet+Nant/MsBuild If you have 100+ developers, you necessarily have a continuous build, and I m 100% sure that you can script
        Message 3 of 22 , Nov 17, 2011
        • 0 Attachment
          On Thu, Nov 17, 2011 at 11:48 PM, Michael Mikowski <z_mikowski@...>wrote:

          > **
          >
          >
          > Our official JSLint utility is kept in SCMS, and changes about once per
          > quarter. It is almost always adjusted to meet our standards that deviate
          > from the JSLint way.
          >
          > +1
          In my company, we use SVN+CCNet+Nant/MsBuild

          If you have 100+ developers, you necessarily have a continuous build, and
          I'm 100% sure that you can script your own build automation.
          When people commit their source, the source could be automatically cleaned
          (or you can clean it once, and force the developers to follow the rules).
          Then, your build process should parse JS sources with JSLint, and block the
          build if there are errors.
          The goal of breaking the build is to force developers to acquire good
          programming habits. It's very difficult to change habits, because nobody
          wants to follow new rules.
          Once the sources have been checked against your coding rules, the process
          should run some unit tests, to validate that the basic functions are not
          broken.

          I agree that this solution is quite "brute", but you should see JsLint as
          an ally instead of an enemy.
          Personally, I tended to fight against software until I stopped trying to
          force my wishes on it, and everything went smoothly afterwards.

          Alternatively, you can use a modified version of JsLint in your build
          process, and upgrade your local version every 6 months, as the parent post
          explained.

          JC


          [Non-text portions of this message have been removed]
        • Nagy Endre
          Hi everyone, maybe it s a little offtopic sorry, but can anyone explain why this inside the o object is refer to window ? Why it s not refer to the o
          Message 4 of 22 , Nov 18, 2011
          • 0 Attachment
            Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why "this" inside the "o" object is refer to window ?
            Why it's not refer to the "o" object if we are inside there? I want to access from the returned object in function "f" the "o.p" property without using "o". Thanks!

            var p = 2,
                o  =  {
                    p: "a",
                    f: (function (m) {
                        return {
                            l: m.p
                        };
                    }(this))
                };

            p = o.f.l;

            Endre


            [Non-text portions of this message have been removed]
          • z_mikowski@yahoo.com
            Javascript does not provide block scope, only functional scope. Therefore the this in your code takes the value as provided to the enclosing function. You
            Message 5 of 22 , Nov 18, 2011
            • 0 Attachment
              Javascript does not provide block scope, only functional scope. Therefore the 'this' in your code takes the value as provided to the enclosing function. You could use the module pattern to get the results you are seeking, e.g.

              var o = function (){
              // private stuff
              return {
              p : "a",
              // rest of object here
              };
              };



              Nagy Endre <forewer2000@...> wrote:

              >
              >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why "this" inside the "o" object is refer to window ?
              >Why it's not refer to the "o" object if we are inside there? I want to access from the returned object in function "f" the "o.p" property without using "o". Thanks!
              >
              >var p = 2,
              >    o  =  {
              >        p: "a",
              >        f: (function (m) {
              >            return {
              >                l: m.p
              >            };
              >        }(this))
              >    };
              >
              >p = o.f.l;
              >
              >Endre
              >
              >
              >[Non-text portions of this message have been removed]
              >


              [Non-text portions of this message have been removed]
            • Rob Richardson
              Try this: var p = 2, o = { p: a }; o.f = (function (m) { return { l: m.p }; }(o)); p = o.f.l; Or this: var p = 2, o = { p: a }; o.prototype.f =
              Message 6 of 22 , Nov 18, 2011
              • 0 Attachment
                Try this:

                var p = 2,
                o = {
                p: "a"
                };
                o.f = (function (m) {
                return {
                l: m.p
                };
                }(o));
                p = o.f.l;

                Or this:

                var p = 2,
                o = {
                p: "a"
                };
                o.prototype.f = function () {
                return {
                l: this.p
                };
                };
                p = o.f.l;

                Rob


                -----Original Message-----
                From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
                Behalf Of Nagy Endre
                Sent: Friday, November 18, 2011 7:13 AM
                To: jslint_com@yahoogroups.com
                Subject: [jslint] this question




                Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why
                "this" inside the "o" object is refer to window ?
                Why it's not refer to the "o" object if we are inside there? I want to
                access from the returned object in function "f" the "o.p" property without
                using "o". Thanks!

                var p = 2,
                o = {
                p: "a",
                f: (function (m) {
                return {
                l: m.p
                };
                }(this))
                };

                p = o.f.l;

                Endre

                [Non-text portions of this message have been removed]
              • stauren
                I don t think this is about block scope or functional sope. This is probably because the function is executed when the script is being parsed, at which time
                Message 7 of 22 , Nov 20, 2011
                • 0 Attachment
                  I don't think this is about block scope or functional sope. This is
                  probably because the function is executed when the script is being parsed,
                  at which time the outer object is not fully established, so the the keyword
                  'this' points to the window object.

                  Another funny aspect of javascript.

                  ---
                  stauren (畅)
                  blog : http://stauren.net
                  email : stauren@...


                  On Sat, Nov 19, 2011 at 12:19 AM, <z_mikowski@...> wrote:

                  > **
                  >
                  >
                  > Javascript does not provide block scope, only functional scope. Therefore
                  > the 'this' in your code takes the value as provided to the enclosing
                  > function. You could use the module pattern to get the results you are
                  > seeking, e.g.
                  >
                  > var o = function (){
                  > // private stuff
                  > return {
                  > p : "a",
                  > // rest of object here
                  > };
                  > };
                  >
                  >
                  > Nagy Endre <forewer2000@...> wrote:
                  >
                  > >
                  > >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain
                  > why "this" inside the "o" object is refer to window ?
                  > >Why it's not refer to the "o" object if we are inside there? I want to
                  > access from the returned object in function "f" the "o.p" property without
                  > using "o". Thanks!
                  > >
                  > >var p = 2,
                  > > o = {
                  > > p: "a",
                  > > f: (function (m) {
                  > > return {
                  > > l: m.p
                  > > };
                  > > }(this))
                  > > };
                  > >
                  > >p = o.f.l;
                  > >
                  > >Endre
                  > >
                  > >
                  > >[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]
                • Nagy Endre
                  Yes, i realized that in {a: this} the value of a is the window value, not what we expect, because at runtime probably the object is not created yet, so
                  Message 8 of 22 , Nov 21, 2011
                  • 0 Attachment
                    Yes, i realized that in {a: this} the value of "a" is the "window" value, not what we expect, because at runtime probably the object is not created yet,
                    so only a method that is called later could have the correct "this" value.

                    I think it would be great if JSLINT could display an error in this situation like:
                    var o = {
                        a : this;
                    };

                    Because i think is there a little confusion here what will be the value of "this".



                    ________________________________
                    From: stauren <liuch.pku@...>
                    To: jslint_com@yahoogroups.com
                    Sent: Monday, November 21, 2011 9:49 AM
                    Subject: Re: [jslint] this question


                     
                    I don't think this is about block scope or functional sope. This is
                    probably because the function is executed when the script is being parsed,
                    at which time the outer object is not fully established, so the the keyword
                    'this' points to the window object.

                    Another funny aspect of javascript.

                    ---
                    stauren (畅)
                    blog : http://stauren.net
                    email : stauren@...

                    On Sat, Nov 19, 2011 at 12:19 AM, <z_mikowski@...> wrote:

                    > **
                    >
                    >
                    > Javascript does not provide block scope, only functional scope. Therefore
                    > the 'this' in your code takes the value as provided to the enclosing
                    > function. You could use the module pattern to get the results you are
                    > seeking, e.g.
                    >
                    > var o = function (){
                    > // private stuff
                    > return {
                    > p : "a",
                    > // rest of object here
                    > };
                    > };
                    >
                    >
                    > Nagy Endre <forewer2000@...> wrote:
                    >
                    > >
                    > >Hi everyone, maybe it's a little offtopic sorry, but can anyone explain
                    > why "this" inside the "o" object is refer to window ?
                    > >Why it's not refer to the "o" object if we are inside there? I want to
                    > access from the returned object in function "f" the "o.p" property without
                    > using "o". Thanks!
                    > >
                    > >var p = 2,
                    > > o = {
                    > > p: "a",
                    > > f: (function (m) {
                    > > return {
                    > > l: m.p
                    > > };
                    > > }(this))
                    > > };
                    > >
                    > >p = o.f.l;
                    > >
                    > >Endre
                    > >
                    > >
                    > >[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]




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