Tuesday, April 05, 2005

Where to start

Where do you start when you have a new task delivered to you? I'm assuming now that the requirements are there and clear enough to procede (breathtaking assumption, isn't it)? What do you look for as you do your analysis?

I find that while I am going through the usual business of identifying objects (nouns) and actions (methods) I'm looking for patterns (not the GOF type — not yet) and symmetry. These are keys to simplification.

Take for example, a simple little brain teaser where one of the key action requires concatenating symbols. Groups of symbols may be joined by operators; in other words any pair of symbols may be separated by an operator or abutted directly. Where's the symetry? Lets restate that last bit: any pair of symbols may be separated by an operator or nothing. But nothing can just be an "operator" object that contains an empty string, for example. In the real world symmetry is broken; in our solution space, we can restore the broken symmetry and make our code that little bit simpler and more elegant:

Here's the code (Ruby) I wrote:


@sep = { "+" => "-", "-" => "", "" => "+" }



It's a hash (associative array) that lets me look up a value in terms of a current value.
Pure rotational symetry.

Show the full teaser (complete with code).

0 Comments:

Post a Comment

<< Home