top | item 15219354

(no title)

enkay | 8 years ago

In practice, DRY in CSS ends up making code very hard to maintain. It creates ghost side effects where you change something on one page and break something on another page unknowingly.

With the exception of a few elements that don't really change at all from one page another like buttons, doing a little bit of copy pasting or search and replace between files is easier.

Sure, you might forget to update one page or component here and there, but at least it won't be broken. Better a component is inconsistent in style but functional than broken.

Using a few variables for things like color and spacing can also help minimize this problem.

Keeping most of my CSS components encapsulated and "namespaced" has worked a lot better in practice than trying to make everything reusable and coupled together in ways that you'll forget about when you have to come back to that project a few months later.

discuss

order

kingkool68|8 years ago

Couldn't agree more. I finished some refacotring of a CSS done with the DRY mantra and there were so many hidden gotchas. When I changed one thing it would end up breaking a number of unrelated things.