Wednesday, August 15, 2007

Design: Top-Down or Bottom-Up?

Once, I prepared a session on practices for good design, symptoms of bad design, time given to design, giving considerable attention to interfaces, testable design, loosely coupled design, cohesive design, principles of good design, test-first design...

When I got to real life, I found myself following the same old practices of almost not going into design at all.
As before, I started writing code immediately, doing all things in main() with a just-get-it-done attitude, when things finally work I start to refactor code in the structured old fashion - just putting common behavior into functions, then when things begin to be slightly complex I eventually start ask my self what about classes, responsibilities of them, relations between them, interfaces ...etc.

I don't know how to follow all these practices and design guidelines from the start. Whatever you're aware of problem domain and requirements are neat, you never see things clearly until you get your hands into solving the problem.

It's unreasonable to start designing thing you don't know, or writing test cases (in TDD culture) for something you don't grasp fully. It's natural to improve incrementally, nothing could get perfect from one shot, so there is no one happy design you'll adhere to from the start to the end and your code will be refactored several times until it becomes mature.

2 comments:

  1. * I agree with you that "there is no one happy design you'll adhere to from the start to the end and your code will be refactored several times until it becomes mature."
    * If you start with *simple* functions, and classes from the beginning, then you will gain 2 advantages:
    1- your code will get better by time
    2- you will not need much refactoring later on
    * Tip of the day:
    A fix in-time saves nine ;-)

    ReplyDelete
  2. "The first time you do something, you just do it. The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor." --Don Roberts

    ReplyDelete