Wednesday, December 05, 2007

Bottom Up Modularizing

Many times when I code and think about part of logic that would go well as a function, I just code it inline. Later when things already working I would then extracting it as a function. It feels much easier that way.

It seems the ideal way is to define a program is topdown : we define modules, classes, functions and then fill in the blanks with code. However, I find that it's not always practical to do so. In reality, the situation does not require exclusively top-down or bottom-up, sometimes one feels natural to do than the other.

So, when to do each?. I find that I do the bottom up when closely-similar function does not exist yet or the signature of the function we are thinking is still vaguely defined. It's easier to just code it inline and extract it later. I think bottom up approach help the brain learn more of the problem than when it is forced to solve it from one direction only.

The case is quite similar for the level of class and library. Sometime it's just more convenient to add class on the same project although it seems not a best fit there or it looks like a more general utilities. Later, when we feel like it or the condition has require it, we could extract it as a library.

So, when it is feels right, just code it inline/directly and let things run first then modularize later when needed.

No comments: