CSS preprocessors (Sass, Less, et al) have come up repeatedly in the last few weeks. I have some existing views on the topic that seem to take a lot of preprocessor advocates by surprise. One even suggested I write a blog post about it, so I sat down to do just that, starting off with some research, as I like to do.
Lo! The blog post I was about to write has already been written — several times, in fact:
- “Sass isn’t for me”, by Nathan Borror
- The Problem With CSS Preprocessors, by Miller H. Borges Medeiros
- LESS Sass. More OOCSS, by Blake Haswell
Those are just the first few I found; I’m sure there are many, many more. Plus, the above posts have much more lively and interesting discussions in the comments than would probably happen on my outpost of a blog.
Many of the anti-preprocessor arguments overlap, but they broadly go like this:
- The layer of abstraction a preprocessor adds is not worth the cost of integrating it into an existing workflow (e.g. setting up a development environment, adding team members, maintenance, bug fixing, et al)
- Preprocessors solve problems that could easily be solved with better CSS (e.g. variables and mixins are just classes by another name)
- The CSS output of a preprocessor is less smart than the CSS output of a human
I more or less agree with all of that. Like many of the authors above, I think being able to perform functions and set variables inside of CSS could be very useful; so why not make CSS4 do so? Then we have a single, open standard that browsers already know how to parse and that developers already know how to code.
What’s troubled me since the first time I heard about preprocessors was why on Earth anyone would think to make one. I’ve always found CSS’s syntax both logical and flexible. My complaints with it are few and minor. But then, I do not have a computer science degree.
What I eventually came to realize is that computer programmers do not like CSS because it is not a programming language (see also the relationship of Haml to HTML, which is also not a programming language). Some found that fact so irritating that they resolved to write a CSS-generating programming language with a syntax that made more sense to them. Other programmers were overjoyed to at last be freed from the tyranny of CSS; the rest of us were surprised to find that, unbeknownst to us, one of our favorite tools had actually been terrorizing many people (many smart people, it turns out, which made me wonder if I’m just a moron…).
Ultimately, there may come a day when I find that the utility of preprocessors outweigh their associated costs; enough people — and enough people whom I respect — use them that from a statistical perspective I have to assume this will happen eventually. It just hasn’t happened yet.