YAGNI or do you?
You may know the YAGNI principle in programming. The acronym stands for "you ain't gonna need it". Basically it says that you should only implement what is needed now. You shouldn't try to make the current code account for potential, future features and use cases that nobody has asked for (yet). It's the minimalist software development life style.
I think it is a very valuable principle. Therefore I try hard to live as close to YAGNI as possible. It has saved me numerous times from making overly complicated solutions due to some vague use case that I painted in my mind. I say "try hard" because the temptation to predict the future and save time in the future by doing the work now is so big.
When I first heard about YAGNI 15 years ago or so I got very excited about it–as we often do when we read or hear about new things. Over the time I got more proficient in following this principle. Since I remember my time before and after YAGNI I can confidently say that it was such a big net value on my programming work.
Yet there is one situation where I relax on my strictness following the YAGNI principle:
I apply less YAGNI when I collect data. Collect more–especially metadata–although you don't need the data now because you can't magically recover data that you haven't collected in the first place. At least not easily, sometimes impossible.
For every record of data that I plan to collect I almost always add some metadata to it. These are my go-to candidates: created_at
, updated_at
, version
, created_by
although most of the time I don't need them (immediately). There are also attributes–not only metadata–that you might want to store preemptively.
In code it makes a lot of sense to strictly adhere to the YAGNI principle because you can change the code at any time when the need arises. In contrast with data it's a lot harder or even impossible to get the data later on. Imagine that you figure out later that it would be good to have the created_at
time for past data sets: you can't.
There's also the Datensparsamkeit principle which says that you should only collect and store the least amount of data that your application requires. This seems to be opposed to my relaxation of the YAGNI principle for collecting data. I think it is not because Datensparsamkeit comes from the privacy and personally identifiable data point of view.
It sounds as I'd contradict myself. Maybe! Loosening the belt on YAGNI's still a sharp knife that's better handled with care.
My heuristic is:
- never compromise YAGNI when writing code–you can change the code at any time
- relax YAGNI diligently when you need to store data and see potential for future opportunities.