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

Re: [XP] Test-first and Spec-first

Expand Messages
  • Dossy
    ... I see. ... You miss the point of test-first design and literate programming, maybe? disable_events() should be defined earlier than when it s used. It s
    Message 1 of 17 , Dec 31, 2001
    • 0 Attachment
      On 2001.12.31, Glew, Andy <andy.glew@...> wrote:
      > > Here's my lame attempt at a 5 minute refactoring,
      > > without knowing what I'm actually implementing:
      >
      > Yep. You are missing the point:
      > I am trying to show *how* to disable the counters, etc.,
      > alomg with a test to show that things aren't counted
      > when disabled, and are counted when enabled.

      I see.

      > > HW.disable_events(ALL_COUNTERS);
      >
      > If the reader has to go to another section to see
      > the definition of disable_events(...) --- well, I will
      > have just lost another reader.

      You miss the point of test-first design and literate
      programming, maybe?

      disable_events() should be defined earlier than when
      it's used. It's like reading a story book: if you
      start from a middle chapter, the author has no
      responsibility if you don't understand the plot
      that's been established in the preceeding chapters
      that you didn't read.

      > > Basically, build a higher-level API on top of your "nitty gritty"
      > > stuff. Handy for when you want to be able to pick up that API
      > > and port it to different lower-level systems -- your applications
      > > don't necessarily need to change.
      >
      > Like I said, you're missing the point.
      >
      > It's the "nitty gritty" stuff that I'm documenting.
      > I'M DESIGNING THE HARDWARE
      > and trying to tell people how to use it.

      testDisableEvents() {
      // this is how you disable events, wrapped by disable_events()
      HW.wrmsr(...);
      }

      testEnableEvents() {
      // this is how you enable events, wrapped by enable_events()
      HW.wrmsr(...);
      }

      testCountEvents() {
      // this is how you count events, wrapped by count_events()
      HW.rdmsr(...);
      }

      testIgnoredEvents() {
      disable_events();
      signal_event(...);
      assert(count_events(...) == 0);
      }

      testCountedEvents() {
      enable_events(...);
      signal_event(...);
      assert(count_events(...) == 1);
      }

      etc.

      -- Dossy

      --
      Dossy Shiobara mail: dossy@...
      Panoptic Computer Network web: http://www.panoptic.com/
      "He realized the fastest way to change is to laugh at your own
      folly -- then you can let go and quickly move on." (p. 70)
    • Laurent Bossavit
      ... Maybe you could code up something that makes *these* executable ? ... Have a look at http://www.erights.org and their Updoc framework.
      Message 2 of 17 , Jan 1, 2002
      • 0 Attachment
        > Examples of identifiers:
        > a foo f154agg
        > Examples of non-identifiers:
        > 1a a^b 87887

        Maybe you could code up something that makes *these* executable ?

        > I am sure that the authors of programming books, like the "Pragmatic
        > Programmer", have done a lot of tool work towards making examples
        > executable. My usual request for pointers to tools available for reuse.

        Have a look at
        http://www.erights.org
        and their Updoc framework.
        http://www.erights.org/elang/tools/updoc.html
        -[Morendil]-
        I'm in total control, but don't tell my wife.
      • Laurent Bossavit
        ... Yup. And we know why... If you were writing the code that passes the test along with writing the tests, you would eventually build up - in the names of the
        Message 3 of 17 , Jan 1, 2002
        • 0 Attachment
          > Test-in-spec first Literate Programming seems to work okay for simple
          > examples, but gets contrived for more complicated ones.

          Yup. And we know why... If you were writing the code that passes the
          test along with writing the tests, you would eventually build up - in
          the names of the classes or functions or whatever - a vocabulary of
          higher-level concepts, which would turn out to be very useful for
          expressing tests at the next higher level.

          -[Morendil]-
          Press Ctrl-Alt-Del to continue
        • Glew, Andy
          ... Thanks. I ve looked at ANTLR in the past, but never used it, and had forgotten it.
          Message 4 of 17 , Jan 3, 2002
          • 0 Attachment
            > do you know of ANTLR, its a combined Lex/yacc-tool in Java.

            Thanks. I've looked at ANTLR in the past, but never used
            it, and had forgotten it.
          • Glew, Andy
            ... Maybe. Trouble is, I m writing a reference book, not a story book. Most people look something up in the table of contents or the index, and jump to the
            Message 5 of 17 , Jan 3, 2002
            • 0 Attachment
              > You miss the point of test-first design and literate
              > programming, maybe?
              >
              > disable_events() should be defined earlier than when
              > it's used. It's like reading a story book: if you
              > start from a middle chapter, the author has no
              > responsibility if you don't understand the plot
              > that's been established in the preceeding chapters
              > that you didn't read.

              Maybe.

              Trouble is, I'm writing a reference book, not a story book.
              Most people look something up in the table of contents
              or the index, and jump to the section that talks about
              what they need to know.

              If this is the case, should I not be trying to use test first
              literate programmimg?

              I hope not: I think that it's working out pretty well.
              I find I just need to code things more obviously than
              normal object oriented, with it's many levels of indirection.

              (Indirection solves every coding problem. Removing levels of
              indirection is the solution for understanding.)



              > testDisableEvents() {
              > // this is how you disable events, wrapped by disable_events()
              > HW.wrmsr(...);
              > }

              Umm, no: the database defines how to disable events.
              I do not know a priori how to disable events.
            • Glew, Andy
              ... Fair enough. But, I *am* writing that code. And getting it to run the test. The problem seems to be that that whole vocabulary gets in the way of the
              Message 6 of 17 , Jan 3, 2002
              • 0 Attachment
                > > Test-in-spec first Literate Programming seems to work okay for simple
                > > examples, but gets contrived for more complicated ones.
                >
                > Yup. And we know why... If you were writing the code that passes the
                > test along with writing the tests, you would eventually build up - in
                > the names of the classes or functions or whatever - a vocabulary of
                > higher-level concepts, which would turn out to be very useful for
                > expressing tests at the next higher level.

                Fair enough.

                But, I *am* writing that code. And getting it to run the test.

                The problem seems to be that that whole vocabulary
                gets in the way of the specification.
              • Glew, Andy
                ... Did you read the rest of my text? The directly executable form is: Example/tests for identifiers: is_identifier( a ) is_identifier( foo )
                Message 7 of 17 , Jan 3, 2002
                • 0 Attachment
                  > > Examples of identifiers:
                  > > a foo f154agg
                  > > Examples of non-identifiers:
                  > > 1a a^b 87887
                  >
                  > Maybe you could code up something that makes *these* executable ?

                  Did you read the rest of my text? The directly executable form is:

                  Example/tests for identifiers:
                  is_identifier("a")
                  is_identifier("foo")
                  is_identifier("f154agg")
                  Example/tests for non-identifiers:
                  is_identifier("1a")
                  is_identifier("a^b")
                  is_identifier("87887")

                  Trouble is, that's more verbose.

                  Or, are you suggesting CONSing up still another type
                  of semi-literate programming extract filter, that converts
                  from the compact form to a test script wrapped with
                  the non-compact form?

                  > Have a look at
                  > http://www.erights.org
                  > and their Updoc framework.
                  > http://www.erights.org/elang/tools/updoc.html

                  Thanks, will do when I am back online.
                • Glew, Andy
                  Laurent, thanks for the pointer to E/Elang, and Updoc. I m not quite sure what to do with it (Java, not C++), but the more tools like this, the more mistakes I
                  Message 8 of 17 , Jan 3, 2002
                  • 0 Attachment
                    Laurent, thanks for the pointer to E/Elang, and Updoc.
                    I'm not quite sure what to do with it (Java, not C++),
                    but the more tools like this, the more mistakes I can avoid.

                    > Have a look at
                    > http://www.erights.org
                    > and their Updoc framework.
                    > http://www.erights.org/elang/tools/updoc.html



                    Moreover, I am very happy to see a reference to tests degenerating
                    over time as a result of maintenance. Separate post.
                  • Dossy
                    ... Maybe. ... How are you judging it? By how effectively it communicates your ideas to your target audience? Or your perceptions of the product you re
                    Message 9 of 17 , Jan 3, 2002
                    • 0 Attachment
                      On 2002.01.03, Glew, Andy <andy.glew@...> wrote:
                      > If [I'm writing a reference book, and not a story book], should I not
                      > be trying to use test first literate programmimg?

                      Maybe.

                      > I hope not: I think that it's working out pretty well.

                      How are you judging it? By how effectively it communicates
                      your ideas to your target audience? Or your perceptions of
                      the product you're creating based on your own desires?

                      > I find I just need to code things more obviously than
                      > normal object oriented, with it's many levels of indirection.

                      This is probably very true. Reference implementations of
                      solutions to problems tend to not be as elegant or efficient
                      as highly tuned implementations, but they communicate their
                      functionality better, which is usually the goal of a
                      reference implementation.

                      The same probably (my WAG here) applies for other reference
                      materials, such as books. The "code examples" may not be
                      the best for cutting and pasting, but they're probably
                      verbose enough to illustrate the concepts clearly enough
                      so that someone with an understanding gleaned from the
                      reference material can go and write the highly tuned
                      implementation based on their knowledge.

                      > > testDisableEvents() {
                      > > // this is how you disable events, wrapped by disable_events()
                      > > HW.wrmsr(...);
                      > > }
                      >
                      > Umm, no: the database defines how to disable events.
                      > I do not know a priori how to disable events.

                      My point was illustrative, not specific or exact.

                      -- Dossy

                      --
                      Dossy Shiobara mail: dossy@...
                      Panoptic Computer Network web: http://www.panoptic.com/
                      "He realized the fastest way to change is to laugh at your own
                      folly -- then you can let go and quickly move on." (p. 70)
                    • Dinwiddie, George
                      ... It seems that your audience knows WRMSR but does not know HW . Would it be more expressive to say MockHW to let them know that it s code emulating the
                      Message 10 of 17 , Jan 9, 2002
                      • 0 Attachment
                        > -----Original Message-----
                        > From: Glew, Andy
                        > > What's to explain? wrmsr() is obviously a reference to
                        > > Wormser from Revenge
                        > > of the Nerds, so I assume it's doing some sophisticated artifical
                        > > intelligence analysis of the hardware. See, no explanation
                        > > necessary! :)
                        > >
                        > > Sorry, I couldn't resist...
                        >
                        > No, you hit the nail on the instruction.
                        >
                        > HW.wrmsr() is a wrapper for the WRMSR instruction.
                        > Sorry, I don't get to change that last one, I didn't create
                        > it.
                        >
                        > Would it be better to call it HW.write_model_specfic_register()
                        > to be more self documenting?
                        > But then it is less familiar to the bulk of my audience,
                        > who know x86 assembly but not C++

                        It seems that your audience knows "WRMSR" but does not know "HW".
                        Would it be more expressive to say "MockHW" to let them know that
                        it's code emulating the hardware? (or "HWsimulator" might be
                        more familiar to hardware engineers) My point is to accept the
                        assembly language terseness, which is already familiar, but to
                        be verbose everywhere else.

                        It bothers me that you feel each line of test code needs a
                        comment.

                        In another message, you say:
                        > > > Examples of identifiers:
                        > > > a foo f154agg
                        > > > Examples of non-identifiers:
                        > > > 1a a^b 87887
                        > >
                        > > Maybe you could code up something that makes *these* executable ?
                        >
                        > Did you read the rest of my text? The directly executable form is:
                        >
                        > Example/tests for identifiers:
                        > is_identifier("a")
                        > is_identifier("foo")
                        > is_identifier("f154agg")
                        > Example/tests for non-identifiers:
                        > is_identifier("1a")
                        > is_identifier("a^b")
                        > is_identifier("87887")
                        >
                        > Trouble is, that's more verbose.

                        Consider wrapping is_identifier() with larger methods are_identifiers(...)
                        and are_not_identifiers(...) if this is a problem.

                        Hope this helps,
                        George
                      Your message has been successfully submitted and would be delivered to recipients shortly.