YAGNI — You’re Aren’t Gonna Need It

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?

  • a Long was indeed the simplest thing I could do to design the link, as I didn’t need any other class to be designed to get my first class running
  • however, refactoring it into a real object is not easy; in fact, it is quite risky, as many places in the code will be changed (tests, Hibernate requests, equals() and hashcode() implementations). In fact, I tried and wasted a full day on it.
  • I think I’ll eventually have to remove it entirely before re-introducing the link between the two objects
  • 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!

    About Eric Lefevre-Ardant

    Independent technical consultant.
    This entry was posted in agile, java. Bookmark the permalink.

    2 Responses to YAGNI — You’re Aren’t Gonna Need It

    1. Sadek Drobi says:

      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!

    Leave a Reply

    Your email address will not be published.