by akdetrick · 14y ago · 0 comments
Both are elegant ways of handling the same task, but I don't think one is much more DRY than the other.
I'd argue that it's more correct to describe a class once and apply it to many elements (OOCSS) than it is to describe it many times over and apply it to each element individually (Sass @extend).
edit After more reading, they are most definitely not degenerate forms of mixins. Placeholders FTW!
.hello { color: red; }
.world { @extends .hello; background: blue }
...it would compile to something like this:
.hello, .world { color: red; }
.world { background: blue; }
na'mean?
What makes you say that the Sass approach is describing it "many times over"? It's described in one place: the %placeholder declaration. There are three steps in the process:
+ Describe the pattern. + Apply the pattern to components. + Apply the components to elements.
In OOCSS, you:
+ Describe the pattern once. + Apply the pattern n times per component. + Apply the component n times per element.
In OOSass, you:
+ Describe the pattern once. + Apply the pattern once per component. + Apply the component n times per element.
The OOSass is much DRYer because if you've decided already that all .dropdown-menu-item's are going to be `.media` patterns, you do that once. You don't have to keep repeating that decision every time you write a new dropdown.