DEV Community

Discussion on: Coding basics: DRY programming

Collapse
 
pentacular profile image
pentacular

One point that is often overlooked with DRY is that you should repeat yourself when two things solve different problems (that is, mean different things) coincidentally in the same way.

Otherwise you'll introduce an accidental dependency between two things that are only accidentally the same.

Really, it should be Don't Repeat Your Meanings, but that's not so catchy.

Collapse
 
_garybell profile image
Gary Bell

True. That's one of those things that comes with time and experience, though. Something which can't easily be taught.

The problem with things like principles like DRY, YAGNI, and SOLID are that they are, ultimately, ideals. It's not always straightforward to keep code adhering to all of those due to time and/or budget constraints, as well as the human element i.e. developers. They are more like guidelines which you should be conscious of when developing, but be aware you aren't likely to stick to them all of the time.