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

optionally allow with?

Expand Messages
  • smparkes@ymail.com
    I normally don t use with: never in production code. The one case I do like it is in test drivers. I have a test object which has a lot of methods (BDD:
    Message 1 of 6 , Jan 22, 2010
    • 0 Attachment
      I normally don't use with: never in production code. The one case I do like it is in test drivers. I have a test object which has a lot of methods (BDD: describe, it, expect, before, after, ...). I don't want the test driver to make these global but I hate having to call them against the driver object and/or var them in every test file. With'ing the test object makes the tests much cleaner w/o cluttering the global namespace. Performance doesn't matter and if it breaks something, it only breaks a test.

      Make with optionally allowed?
    • walfisch_in_the_sea
      (function (o) { o.describe(); o.it(); o.expect(); o.before(); o.after(); }(testobject)); No new globals. JSLint is a subset of Javascript for a reason. With
      Message 2 of 6 , Jan 22, 2010
      • 0 Attachment
        (function (o) {

        o.describe();
        o.it();
        o.expect();
        o.before();
        o.after();

        }(testobject));

        No new globals.

        JSLint is a subset of Javascript for a reason.
        "With" is buggy implemented, why do you run tests with elements you cannot rely on?

        with (testobject) {
        describe();
        }

        If testobject has no describe, it should break your code (that's what you might have wanted to test).
        If there is a describe method in that scope (or even global), you will never learn your object has not the method you thought it would have. The test would be absurd.

        Don't use it.
        If JSLint had an exceoption for every bad practice, it would be no code quality tool anymore.



        --- In jslint_com@yahoogroups.com, "smparkes@..." <smparkes@...> wrote:
        >
        > I normally don't use with: never in production code. The one case I do like it is in test drivers. I have a test object which has a lot of methods (BDD: describe, it, expect, before, after, ...). I don't want the test driver to make these global but I hate having to call them against the driver object and/or var them in every test file. With'ing the test object makes the tests much cleaner w/o cluttering the global namespace. Performance doesn't matter and if it breaks something, it only breaks a test.
        >
        > Make with optionally allowed?
        >
      • smparkes@ymail.com
        Note that I m not with ing any of my own objects, I m withing the test framework itself, and only that. Actually, I have a couple of them that I might with.
        Message 3 of 6 , Jan 22, 2010
        • 0 Attachment
          Note that I'm not with'ing any of my own objects, I'm withing the test framework itself, and only that. Actually, I have a couple of them that I might with.

          The difference is the DSL-ish-ness of the result:

          (function(){
          with(jasmine){
          describe("my type",function(){
          it("should do the right thing",function(){
          expect("something").toBe(true);
          });
          });
          };
          }());


          Adding a bunch of "o."s in there bugs ... but that's personal and I'm not trying to convince anyone of that. Most test frameworks just bash the global scope, which I don't like either. I could var up all the functions at the top of the closure, so the ugliness is just in one place, but there are too many functions to duplicate all that code.

          Or I could just have jasmine export a string with all the var statements, and then eval that. jslint won't like that, but it does provide a setting where I can say it's okay to eval in this file.

          Of course, you can't just var up the functions since they might need closures to get the proper object binding when called that way.

          All I'm suggesting is that there be a similar switch for with ...

          ... which I just realized, is actually not implemented at all, so it can't actually be turned off. Hmmm ... maybe I'll implement it for myself.

          So far, I don't see any particularly big drawbacks to this one use case and the result is significantly prettier to me ...
        • walfisch_in_the_sea
          ... Do that, you re right. I still think with is wicked, but don t let me hinder you implementing it.
          Message 4 of 6 , Jan 23, 2010
          • 0 Attachment
            > ... which I just realized, is actually not implemented at all, so it can't actually be turned off. Hmmm ... maybe I'll implement it for myself.

            Do that, you're right. I still think "with" is wicked, but don't let me hinder you implementing it.



            --- In jslint_com@yahoogroups.com, "smparkes@..." <smparkes@...> wrote:
            >
            > Note that I'm not with'ing any of my own objects, I'm withing the test framework itself, and only that. Actually, I have a couple of them that I might with.
            >
            > The difference is the DSL-ish-ness of the result:
            >
            > (function(){
            > with(jasmine){
            > describe("my type",function(){
            > it("should do the right thing",function(){
            > expect("something").toBe(true);
            > });
            > });
            > };
            > }());
            >
            >
            > Adding a bunch of "o."s in there bugs ... but that's personal and I'm not trying to convince anyone of that. Most test frameworks just bash the global scope, which I don't like either. I could var up all the functions at the top of the closure, so the ugliness is just in one place, but there are too many functions to duplicate all that code.
            >
            > Or I could just have jasmine export a string with all the var statements, and then eval that. jslint won't like that, but it does provide a setting where I can say it's okay to eval in this file.
            >
            > Of course, you can't just var up the functions since they might need closures to get the proper object binding when called that way.
            >
            > All I'm suggesting is that there be a similar switch for with ...
            >
            > ... which I just realized, is actually not implemented at all, so it can't actually be turned off. Hmmm ... maybe I'll implement it for myself.
            >
            > So far, I don't see any particularly big drawbacks to this one use case and the result is significantly prettier to me ...
            >
          • walfisch_in_the_sea
            You inspired me to do that today: http://github.com/Walfisch/boring-assert/ A Javascript test framework that uses chaining, the code to use looks like that
            Message 5 of 6 , Jan 23, 2010
            • 0 Attachment
              You inspired me to do that today:
              http://github.com/Walfisch/boring-assert/

              A Javascript test framework that uses chaining,
              the code to use looks like that then (without with and without "o."):

              assert(!!document.body, "document.body should exist").

              assert.
              print(!!document.body, "document.body should exist").
              print(!document.body, "document.body shall not exist");

              assert.
              suite("Suite 1", function () {
              assert.print(typeof alert === "function", "alert is function");
              }).
              suite("Suite 2", function () {
              assert.
              print(0.1 + 0.2 === 0.3, "0.1 + 0.2 === 0.3").
              print(0.5 - 0.2 === 0.3, "0.5 - 0.2 === 0.3");
              });



              --- In jslint_com@yahoogroups.com, "smparkes@..." <smparkes@...> wrote:
              >
              > Note that I'm not with'ing any of my own objects, I'm withing the test framework itself, and only that. Actually, I have a couple of them that I might with.
              >
              > The difference is the DSL-ish-ness of the result:
              >
              > (function(){
              > with(jasmine){
              > describe("my type",function(){
              > it("should do the right thing",function(){
              > expect("something").toBe(true);
              > });
              > });
              > };
              > }());
              >
              >
              > Adding a bunch of "o."s in there bugs ... but that's personal and I'm not trying to convince anyone of that. Most test frameworks just bash the global scope, which I don't like either. I could var up all the functions at the top of the closure, so the ugliness is just in one place, but there are too many functions to duplicate all that code.
              >
              > Or I could just have jasmine export a string with all the var statements, and then eval that. jslint won't like that, but it does provide a setting where I can say it's okay to eval in this file.
              >
              > Of course, you can't just var up the functions since they might need closures to get the proper object binding when called that way.
              >
              > All I'm suggesting is that there be a similar switch for with ...
              >
              > ... which I just realized, is actually not implemented at all, so it can't actually be turned off. Hmmm ... maybe I'll implement it for myself.
              >
              > So far, I don't see any particularly big drawbacks to this one use case and the result is significantly prettier to me ...
              >
            • Dan McNeil
              Woops... this is what that last missive was RE: ________________________________ From: walfisch_in_the_sea To:
              Message 6 of 6 , Jan 23, 2010
              • 0 Attachment
                Woops... this is what that last missive was RE:



                ________________________________
                From: walfisch_in_the_sea <christian.wirkus@...>
                To: jslint_com@yahoogroups.com
                Sent: Sat, January 23, 2010 11:58:32 AM
                Subject: [jslint] Re: optionally allow with?


                You inspired me to do that today:
                http://github. com/Walfisch/ boring-assert/

                A Javascript test framework that uses chaining,
                the code to use looks like that then (without with and without "o."):

                assert(!!document. body, "document.body should exist").

                assert.
                print(!!document. body, "document.body should exist").
                print(!document. body, "document.body shall not exist");

                assert.
                suite("Suite 1", function () {
                assert.print( typeof alert === "function", "alert is function");
                }).
                suite("Suite 2", function () {
                assert.
                print(0.1 + 0.2 === 0.3, "0.1 + 0.2 === 0.3").
                print(0.5 - 0.2 === 0.3, "0.5 - 0.2 === 0.3");
                });

                --- In jslint_com@yahoogro ups.com, "smparkes@.. ." <smparkes@.. .> wrote:
                >
                > Note that I'm not with'ing any of my own objects, I'm withing the test framework itself, and only that. Actually, I have a couple of them that I might with.
                >
                > The difference is the DSL-ish-ness of the result:
                >
                > (function(){
                > with(jasmine) {
                > describe("my type",function( ){
                > it("should do the right thing",function( ){
                > expect("something" ).toBe(true) ;
                > });
                > });
                > };
                > }());
                >
                >
                > Adding a bunch of "o."s in there bugs ... but that's personal and I'm not trying to convince anyone of that. Most test frameworks just bash the global scope, which I don't like either. I could var up all the functions at the top of the closure, so the ugliness is just in one place, but there are too many functions to duplicate all that code.
                >
                > Or I could just have jasmine export a string with all the var statements, and then eval that. jslint won't like that, but it does provide a setting where I can say it's okay to eval in this file.
                >
                > Of course, you can't just var up the functions since they might need closures to get the proper object binding when called that way.
                >
                > All I'm suggesting is that there be a similar switch for with ...
                >
                > ... which I just realized, is actually not implemented at all, so it can't actually be turned off. Hmmm ... maybe I'll implement it for myself.
                >
                > So far, I don't see any particularly big drawbacks to this one use case and the result is significantly prettier to me ...
                >







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