4 ms·
Yes, a better description of DRY might be "one place to change a fact". It's a specific example of my general rule in designing my projects: things that tend t
by bcrosby95 6y ago
Yes, a better description of DRY might be "one place to change a fact".
It's a specific example of my general rule in designing my projects: things that tend to change together should be closer together.
- brightball 6y agoI really like that explanation and I’m probably going to steal it. :)
- dgb23 6y agoPerfect! It implies that there is something you have to think about before you think about DRY. This "something" is representation of facts and data. The universal idea of pulling data out of code seems to be as old as programming itself and is proposed by Unix/C programmers and Lispers alike. After pulling out the data, the code becomes simpler, more general and more composable. The data structure then often reveals repetition that is not redundancy: If you look at a configuration file, a SQL table or a REST response that has repetition, it becomes clear that it represents different facts (to use your term) that happen to have the same values (Alice and Bob have the same age). This form or repetition is fine, correct and often interesting! So by the practice of pulling out data from code we get DRY (by the definition of the authors) code. However there is also also another form of repetition that is a bit more subtle: boilerplate. There, the representation of an algorithm (as code) is drowned in noise that does not convey the intent and the flow of what is happening. To increase the signal to noise ratio in code that is already(!) DRY but clouded by boilerplate, one needs a way to reduce syntax itself, which can be achieved by meta-programming and DSLs.