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

Re: [XP] Test Objectives (was: Re: Unit Test Challenge II)

Expand Messages
  • C. Keith Ray
    ... The bad things that HAVE happened (which were caught by assertions) were writing bad tests and bad code because I ve forgotten the constraints of a class,
    Message 1 of 263 , Apr 1, 2002
    • 0 Attachment
      on 2002.03.31 7:06 PM, Ron Jeffries at ronjeffries@... wrote:

      > Around Sunday, March 31, 2002, 10:01:28 PM, C. Keith Ray wrote:
      >
      >> on 2002.03.31 5:28 PM, Ron Jeffries at ronjeffries@... wrote:
      >
      >>> Why don't you replace the asserts with comments?
      >
      >> Because comments don't come to life when some piece of code provides some
      >> other piece of code bad values. They actively remind me of things I've
      >> forgotten.
      >
      >>> It's easier to act your way into a new way of thinking
      >>> than to think your way into a new way of acting. --Millard Fuller
      >
      >> I started doing 'design by contract' before XP, and found it improved my
      >> code. I haven't seen any reason to drop that practice now that I'm doing XP.
      >
      > You're avoiding my question. You claimed that it isn't a matter of not
      > trusting someone or some code. If it isn't, then comments should work
      > just fine.
      >
      > I'm all for design by contract as a technique, though I don't use it
      > myself. But tell us, what bad things do you think would happen if your
      > contract assertions were just comments, instead of actual code?

      The bad things that HAVE happened (which were caught by assertions) were
      writing bad tests and bad code because I've forgotten the constraints of a
      class, or made a mistake.

      The bad things that HAVE happened (when there no assertions) is that a bug
      report is made by the testers or OEM customers about strange behavior, which
      I eventually trace down to some piece of code getting a bad input. My fixes
      involve fixing where the bad input came from, and putting in an assertion to
      document what constitutes good/bad input.

      We do a lot of testing with both "non-production" code and "production
      code", so we're pretty comfortable with assertions being stripped out of the
      final "production" version.

      ----

      C. Keith Ray
      <http://homepage.mac.com/keithray/resume2.html>
      <http://homepage.mac.com/keithray/xpminifaq.html>
    • Ilja Preuß
      ... I don t write many asserts or comments, but *I* would most often prefer asserts before comments because - I always first look at the code if I want to know
      Message 263 of 263 , Apr 6, 2002
      • 0 Attachment
        > Why don't you replace the asserts with comments?

        I don't write many asserts or comments, but *I* would most often prefer
        asserts before comments because

        - I always first look at the code if I want to know what it does. If a
        precondition is significant enough to be written down, it is probably
        significant enough to be spotted early.

        - I most often find it easier to articulate something about code *in*
        code than in natural language.

        - I think if I *don't* find it easy to articulate a significant concept
        about the code in code, that tells me something about the design.

        - Even if I find it easy to articulate an assertion, writing it down
        might nevertheless tell me something about the design I didn't smell
        before.

        - I almost always find it easier to understand code than to understand
        natural language.

        - I am more likely to forget adjusting a comment to changing code than
        adjusting an assert.

        - I think it is easier to refactor an assertion than to refactor a
        comment

        - I simply hate writing comments, whereas I love writing code! ;-)

        There are probably more reasons...

        Regards, Ilja
      Your message has been successfully submitted and would be delivered to recipients shortly.