How to tell that this is not production code
Today I co-wrote some code that I am not so sure about. I don’t think that I want it to ever reach production state.
Here are some of the symptoms encountered while writing it:
- Before running the tests:
- “We are crazy to even try it”
- “There is not way that it is going to work”
- “Complete waste of time”
- “I have no idea what I am doing here, or how it is going to behave”
- After running the tests:
- “I can’t believe it is working”
- “There is no way it should have worked”
- “There is no way I can explain to other developers what we just did”
- “It is not debuggable”
Add that to mad giggles as we wrote the code and tested it. It is a fascinating piece of work, but it is fascinating in the same way as a car wreck.
Just to give you some idea about what I am talking about, the code involved:
- Generic entities (as in Dispatcher<T>)
- NHibernate Hierarchies
- Dependency Injection via Object Builder
The end result is actually fairly clean, you end up with something like this:
Repository< IDispatcher <Order>> .FindOne( Expression.Eq(“DestinationCountry”,”UK”)).Dispatch(order);
It looks nice, until you try to explain how it works.
Each dispatcher has a different argument object, which is mapped via NHibernate to a common table, so you can pass strongly typed arguments to the dispatcher, and NHibernate will deal with all the magic.
The disturbing part is that there is runtime translation of the requested class, and then there is injection of services into the entity. I will leave aside the idea of service entities at the moment, which is not nice as it is.
Adding a new dispatcher involves inheriting from a generic base class, adding NHibernate mapping and adding Object Builder mapping, not for the faint of heart, in my humble opinion.
But, it is generic, configurable and extensible. Recently, it seems like YAGNI has became a mantra for me, as well as the quote: “The most configurable system is java.exe, and it is configured via javac.exe”
Comments
Comment preview