News for hackers. Stuff that matters.
Re:Optimize for Simplicity First by Jtsummers on Thursday February 24, 2022 @09:49AM (#30455340)
It doesn't help that their KISS vs DRY example is a poor one. A single use is already DRY. DRY only applies when you have something getting duplicated, and if there is no duplication then you have nothing to DRY. So really it's KISS vs YAGNI that they're showing, and not KISS vs DRY.

Better would have been to show multiple, similar, validation procedures and then the DRY version, at least that would have been an appropriate use of the DRY principle. But even then, marshaling and unmarshaling the data like that is bordering on moronic. Generic, yes, but still bad code. Certainly unsuitable for any tight loops, and it only contains one notion of validation (is data present). It does not handle the case where the empty string may be a valid value. It does not include any kind of invariant checks (if foo.X in A then foo.Y in f(A), 1 < foo.Z < 1000, etc.). Once your validation routines include those, it'll become obvious that there is no good generic validation routine and having one validation routine per structure is DRY.

There are no comments on this comment yet.