Scalable and Maintainable CSS Approaches
cwebbdesign.tumblr.com
cwebbdesign.tumblr.com
In other words, if you want to build something maintainable, start thinking about all the ways you can help people not write custom CSS at all.
Also, LESS and SASS at their core do little to help with this problem, and can even hurt you with unintentional specificity (due to nesting) that hurts reusability. Mixins help you think "reusability" but they can really easily be misused in ways similar to how people are misusing CSS right now. This is by no means an attack on LESS/SASS, which I love. It is just a reaction to working on a large project that is making the switch and seeing the fallout.
This article focused on the first part and even compares different approaches, but misses the point that OOCSS is advocating a process overhaul, not just a change to the way that you write CSS.
When I say help people not write custom CSS, I am referring to reuse. Writing the code the right way is of course a pre-requisite, but from experience, not nearly enough.
Quick example, OOCSS way of making the notion of 'fancifying a thing', is to make a separate class to represent 'fanciness'.
.fancy { color: hotpink; font-style: italic }
.thing { width: 100px; height: 40px }
Then in your HTML apply both classes to make a fancy thing: <div class="thing fancy">ta-da</div>Whereas in SASS you could do that with a mixin instead:
@mixin fancy { color: hotpink; font-style: italic }
.fancy-thing { width: 100px; height: 40px; @include fancy }
And in your HTML, you then apply a single class: <div class="fancy-thing">bam</div>There are advantages of both, and there are clearly variations you could make on the SASS version (i.e. you could make a separate thing mixin too, then mix both into a single fancy-thing class - making the thing concept as reusable as in the CSS version).
Personally I like the level of understanding that doing it the CSS way brings (note this is also an example of the separating 'skin' from 'structure' idea, which I think is very valuable). You could argue that it could lead to class-itis though. Swings and roundabouts.
I personally love using SASS and in fact (as mentioned by philipwalton) find it highly compatible with OOCSS. However, as with any tool, I advocate for thoughtful and critical implementation. I tend to suggest that anytime the final CSS file contains a large amount of repetitive styles or deeply nested selectors it's time to consider refactoring.
More important than any one methodology is consistency and documentation, no one wants to pick up a project with 'genius' abbreviated class names without some example markup!
I don't get the DRY CSS approach of wanting to avoid changing HTML. CSS changes are much more expensive, as they can affect the design on unrelated pages (especially if you don't write modular CSS), which means more testing.
And are there any real world use cases or benefits of "semantic class names"? If not, and if you think they hurt maintainability, why would anyone advocate them?
> And are there any real world use cases or benefits of
> "semantic class names"?
Yes. Class names tell what the stuff is, CSS rules tell how to style it.
Once you see blue 14px text on the left which has class "red-12px-right" you are enlightened.'red-12px-right' is a stupid class name (and a strawman). A better example would be 'heading-primary', instead of a "semantic" approach like '.news h2 { }' (which could have the same styles as '.blogs h1' and '.members h3'...)