3 ms·
You say so much that I agree with, except your core thesis. YAGNI must be applied with DRY, yes. Code is disposable (maybe-leaning-to-yes), data is not, yes.
by moron4hire 11y ago
You say so much that I agree with, except your core thesis.
YAGNI must be applied with DRY, yes. Code is disposable (maybe-leaning-to-yes), data is not, yes.
But not properly defining your data is a huge mistake. Torvalds has been noted to say: "git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I'm a huge proponent of designing your code around the data, rather than the other way around, and I think it's one of the reasons git has been fairly successful […] I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important."
Well-documented data structures. Schema is data structure documentation.
Your Point example is good. A Point is not a Size, but an array of numbers could be interpreted as either, or as a Latitude/Longitude pair, or as anything else. How do we know, looking at an array of numbers, what it is meant to be?
But if we knew it was a Point (because the type expressed it as such), then we'd also get to assume we can do point-like things to it.
Of course, YAGNI would suggest not creating a Point and Size classes until you need to differentiate between multiple types of ordered pairs. That's fine. If your system only ever handles point data, then it only ever handles point data and we state that up front, allowing us to assuming "oh, an array of numbers? Must be a point".
But being able to handle different types of data is a feature, and if you prove you need it, then you need it. Write that Point and write that Size class.