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

Re: [XP] fix or rewrite?

Expand Messages
  • Phlip
    From: Arrizza, John ... Making the code assertion-rich, including assertions not required by the tenants of Design by Contract, helps. Just think of it like
    Message 1 of 1 , Apr 3 7:02 AM
    • 0 Attachment
      From: Arrizza, John

      > In my experiences so far with rewriting the hard part is the unit tests.
      > Since the old code was NOT written with testing in mind, the first step
      > invariably is to refactor the class to disentangle itself from the rest of
      > the spaghetti. Once I have a clean strand, I write a unit test for it. I
      > know this is a break from TestBeforeYouRefactor, but if I could write the
      > test without refactoring I would have done it. This is risk#1: you are
      > making changes to the code without a unit test back up.

      Making the code assertion-rich, including assertions not required by the
      tenants of Design by Contract, helps. Just think of it like you are,
      temporarily, your own test rig. And an assertion could call a big function
      that does a lot of checks.

      > I then write as many tests as I can think of. Can I find them all? I don't
      > know. I don't know precisely what the original code did since I did not
      > write it in the first place or it's mine but I've forgotten what it does.
      Of
      > course, there are no tests I can run to see what the code does. This is
      > risk#2: you don't know what the original code does and you are changing
      it.

      Risk#2.5 If you find a bug you can't arbitrarily nuke it on sight. Code you
      have not yet instrumented might have a counter-bug that depends on this bug.
      You must log the bug instead of assert against it, run the program over and
      over again, and if the bug ever happens you must trace back into who called
      it and instrument that.

      > I then refactor everything in the class as best I can.

      Then the fun begins!

      > There are no functional tests except to crank the entire system up and let
      > 'er rip.

      You could keep an installation of the old version around for comparisons...

      Phlip
      ======= http://users.deltanet.com/~tegan/home.html =======
    Your message has been successfully submitted and would be delivered to recipients shortly.