If it is dynamic, it is going to be hard to debug

time to read 2 min | 227 words

Just to clear something before we begin, I'm not talking about static vs. dynamic languages. I'm talking about static vs. dynamic object models. Consider a simple model of a windows application. It has a couple of menu items and an action associated with each menu item. This is really simple. Now bulid the menu dynamically, then try to figure out why the wrong action is called when a button is pressed.

It is much more complicated Now. If we will make it even more dynamic, the action can change the state of the menu, so a different action will be called. Have fun debugging such after three of four such iterations. Somewhere in the chain something went wrong, you just need to understand where, why and how.

The code is elegant, clean and simple, by the way. It is just that the consequences of multiply passes through it are hard to predict accurately over a period of time. This applies to just about all the smart stuff that we do today. IoC and AOP are two great examples, they have the chance of greatly simplify your code, but just try to figure out what you did that made the container give you the wrong interface implementation, or caused the caching AOP to always skip the method.