Wednesday, June 20, 2012

Common Problem solving with fp and oop ways

The fundamental basis of common problem solving is to split a problem into smaller problems, smaller problems with one angle/factor/context at a time.

Then try to solve each one of them in seclusion, avoid mixing contexts as much as possible while solving them.

Now once they are solved individually compose them back to get the grand final solution. It will work if the contexts and the solutions both are composable.

Even with my limited knowledge of functional programming concepts I can see the above scheme fitting it nearly well. While solving it FP way I am focussing exactly on the behavior and the solution. Composition of smaller solution units as functions are deeply engrained in the paradigm. I have just one entity to worry about while composing: function/behavior. Things tend to be precise. Although the learning curve is sharp it tends to fall in place sooner or later.

Now that I have been exposed to little of FP, I have started to realise where object-oriented is not working. With that of mainstream object-oriented concepts, I start with the classes. The splitting of the problem and appearance of classes look cool and encouraging. Things look great and beautiful during the splitting phase. But when the time comes to compose the solutions back to the big picture, it tends to start getting ugly. I think the main reason behind this hurdle is that now we are trying to compose the solution at two levels: class and behavior. If I focus on class composition then the behavior tends to either underfit or overfit the desired solution. If I focus on the behavior composition then the classes start to look mixed and weird. Statefulness of the classes add another level of complexity. So now we have to deal with three types of complexities at a time.

Scala is trying to bridge the gap with its hybrid approach, but have you looked at the trio of class/trait/object? They are so hairy, full of details, so much detail! As expected the functional part is hard anyway.

The contemporary programmers like me are going through so much of flux, confusion, trial and errors and brain bending phases. But it is fun of course. Let the wheels keep rolling. :)

No comments: