A couple of weeks ago, I started working on the objects that needed to be mapped onto the database. As I didn’t know what to do with each of them, I tried to keep things simple by mapping a foreign key into a Long.
A couple of days ago, I realized that this foreign key actually pointed to an object that was now available. Predictable enough, but was I right to map it to a simple Long before?
Designing the first class as simply as I could was the right move. However, that’s not what I did; actually, I had added this foreign key because it was there, not because I needed it. If I had refrained from adding it as all, I wouldn’t have wasted time in trying to refactor it.
All that because I didn’t apply YAGNI properly. A lesson to remember!
I beleive that YagNi law is one of the most defficult to prefectly apply. The problem is that applying it is not fun, we always like to design, to spend a lot of time on paper trying to design something that can live forever, being pragmatic is not easy. Doing what just what is needed is even sometimes annoying and even boaring.
The cost of your decision wasnt that expensive, but comparing to the small addition u did, it quite is! I ve seen weeks of development rolled back because of exactly the same thing, Not respecting this law.
Nowadays i am searching my pleasure more in refactoring, it can be a lot of fun, it can really replace that of predicting conception. I love planning the refactoring, breaking the code and the tests then fixing them back! you can say it became my hobby :p
Anyway, thank you Eric for pointing out this very important point, your example is excellent! a small addition that caused a day of rollbacking!
http://www.dancingmango.com/blog/2007/04/02/the-invisible-lift/