Monday, 14 October 2013

Is SASS making us over-specify??

So one of my bug bears is over-specification.  Why put in a bunch of classes to target an object when just one or two will do?

Over-specification causes:
  • bulky CSS
  • reduced re-use (if it's too specific, then nobody can reuse it, right?)

So I'm a card-carrying, flag-waving under-specifying CSS user.

And then along comes SASS.  SASS who wants you to encapsulate.

.myClass{someStuff:0;
    .ooAnotherSelector{someMoreStuff:0;}
}

Which compiles to:
.myClass .ooAnotherSelector{someMoreStuff:0;}

And while it's all kinda neat and cute and grouped in the .scss file, in the CSS file it comes out as over-specified annoyances.  Well, at least as far as I'm concerned.

The trouble is, the encouragement is to do this, and the compiler can't be modified to tell whether it needs that level of specification or not.  I'd like to tell it to rip out the non-required selectors, but how does it know if they're required or not.

Sigh.