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

26684Re: Uploaded File: "2007-11-18 - Refactoring Challenge - LogicMatrix.zip"

Expand Messages
  • Donald Roby
    Nov 26, 2007
      --- In testdrivendevelopment@yahoogroups.com, "Jeff Grigg"
      <jeffgrigg@...> wrote:
      >
      > --- "Donald Roby" <droby@> wrote:
      > > I played a bit with this. [...] I posted it at my
      > > recently created blog.
      > >
      > > http://donroby.blogspot.com/2007/11/refactoring-challenge.html
      >
      > Good response. Certainly valid. My intention was running more
      > towards existing and proposed language features that could be used to
      > simplify the logic. Coding the matrix as a string (as my tests and
      > code generator do) seems a bit much like doing metaprogramming --
      > creating a Domain Specific Language -- just to simplify a bit of
      > logic. If a two dimensional (or N dimensional) decision matrix that
      > drives code execution is the best representation for some problems,
      > do we need language, tool or library support for it? Would the Fit
      > library and its most common usage patterns provide useful inspiration?
      >
      Yes, this is sort of a metaprogramming approach, moving toward a DSL.

      But a matrix similar to this is a common way of representing this kind
      of decision, so it seemed a sensible path.

      Fit is essentially a DSL for table-driven acceptance testing, so it
      might well provide inspiration for building library support for
      something like this.

      >
      > I simplified the logic to this:
      >
      > . // - - - - !a +a !a +a
      > . // - - - - !b !b +b +b
      > . // !d !c - .X .Z .W .W
      > . // !d +c - .X .X .Z .W
      > . // +d !c - .Y .X .X .Z
      > . // +d +c - .Y .Y .X .X
      >
      > . if (d && !b && (c || !a))
      > . . callback.y();
      > . else if (b && !d && (a || !c))
      > . . callback.w();
      > . else if ((a && !b && !c && !d) || (!a && b && c && !d) || (a && b
      > && !c && d))
      > . . callback.z();
      > . else
      > . . callback.x();
      >

      I'm getting a bit confused. Perhaps a concrete example of decisions
      with more interesting names than a,b,c,d,w,x,y,z would help...

      There are probably examples of more 'real' decision matrices on-line
      somewhere. I'll look for some and try to test-drive a solution to a
      real problem along these lines.

      --
      Don Roby
      <droby@...>
    • Show all 9 messages in this topic