Wednesday, September 01, 2010
If is very powerful construct of programming languages. Most bug fixes involve adding another "if" or handling the else part properly. Many bug fixes would need adding "ifs" at multiple places. I think of "ifs" as design problem. If essentially means doing something different based on some criteria. If multiple functions needs to check for the same criteria and do something (same or different), then what we are really doing is "adding some functionality" which perhaps belongs to a separate object, to all the places we are adding "ifs". May be what we need is a new object/function to abstract that functionality or perhaps declaring a new interface and adding multiple implementations. Ifs allow us to live with design problem by having special cases, whereas the whole point of design is not to have special cases, just simplicity.