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

Re: [XP] How do you test for this....

Expand Messages
  • Rex_Jolliff@notes.ymp.gov
    Michael C. Feathers on 02/28/2001 06:37:54 AM Please respond to extremeprogramming@yahoogroups.com To:
    Message 1 of 9 , Feb 28, 2001
      "Michael C. Feathers" <mfeathers@...> on 02/28/2001 06:37:54 AM

      Please respond to extremeprogramming@yahoogroups.com

      To: extremeprogramming@yahoogroups.com

      cc: (bcc: Rex Jolliff/YM/RWDOE)

      Subject: Re: [XP] How do you test for this....

      Federal Record Status Not Determined

      ----- Original Message -----
      >From: John Carter <john.carter@...>
      >> if( i <= s.end() && *i == '+') {
      >> do something
      >> }
      >> .
      >> I should have coded if( i != s.end() &&...
      >> But I felt that putting in the details detracted from the picture.
      >> Perhaps I should rephrase the question...
      >> How do you write a unit test for fence post errors in a hostile
      >> environment like C++?

      I take exception to such comments, there is no reason to attack
      a development tool just because you dont like it.

      >In C++, I usually compare for inequality on iterators,
      >not relative position. It is a habit from for-loops.
      >So, I probably wouldn't have been bitten by this bug.

      To answer his question, one could easily subclass the string
      class and provide array bounds checking (which could be removed
      from production use if needed, but that is another discussion).
      I noticed that CppUnit subclasses string to add some number
      formatting methods, take a look there if your curious.

      >I don't know of any magic formulas for avoiding
      >fence post errors in C++, but I do know that as a
      >yout' the C programming language taught me to
      >be cautious enough to avoid them. I learned C
      >as a first language, did my share of dancing over core
      >and learned to avoid that. At the end of my first term
      >in Pascal, I was surprised to see other students get
      >index out of bounds errors from the Pascal run-time.
      >I didn't know the run-time did that.

      >Tests don't catch everything. Good programming
      >habits pay dividends. Programmers moving to
      >dynamically typed languages develop new habits.
      >No compiler is going to tell them that a method is
      >not defined, or misspelled, so they arm themselves
      >with other habits.

      I agree with the sentiment here. Language constructs
      that promote complaicency and reliance on the compiler
      to provide condition checking is not necessarily a good
      thing IMHO.

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