CSS style sheets have a habit of growing big and chaotic over time.
There are a lot of rules, hints, and schools of thought that help achieving cleaner CSS. (For example here) However, all those require constant alertness, activity and a lot of discipline on the maintainer's end, with mixed real-world success. As Nicole Sullivan so nicely puts it:
In fact, in most cases, the things we considered best practices were leading to the bad outcomes we sought to avoid. I realized (unpopular though it might be), that we couldn’t make it work out well by trying harder. Each time we start a new project, we think “this time, I’m going to keep the code clean. This time the project will be a shining example of what can be done with CSS.” And without fail, over time, as more content and features are added to the site, the code becomes a spaghetti tangle of duplication and unpredictability.
Are there any efforts to create a language of some sort, with strict structural rules and a merciless compiler, that enforces strict rules that prevent style sheets from becoming spaghetti? The compiled end result would be CSS.
我不知道这样的语言会是什么样子,以及在存在众多可能性和组合的情况下,这是否是一个完全可以解决的问题。
在这个领域有什么研究吗?有什么可以尝试的吗?
一个非常有趣的相关工具是CSS Lint,但是我要问的甚至远不止于此。
编辑: LESS和SASS绝对朝着正确的方向发展,但是它们不是我想要的。它们引入了一些非常好的功能,对于CSS开发人员来说是一个天赐的礼物,但是我要问的是对定义的,强制执行的结构的了解甚至更多。
你检查过指南针吗?Compass是围绕Sass构建的框架。我认为它主要是添加功能和样板代码来添加预定义的库
mixins
和诸如此类的东西。但是,指南针可能甚至更接近您想要的。Compass基于Blueprint,Blueprint是一个简单的CSS框架(可能也值得研究)。对我而言,最好的方法是采用Compass和Sass(或CSS和Blueprint / LESS等类似工具),并编写非常简洁详细的样式指南,在找出最有效的方法时可以加班开发:此事,无论经验如何,都可能是错的。一旦掌握了这些准则,您就可以与Sass,Compass,LESS,Blueprint等机构的人员讨论如何制定经过深思熟虑和“研究”的准则。或者,您可以开始为这些精彩的项目做出贡献,我相信这些项目都是在开源许可证下进行的(Sass在MIT之下,LESS在Apache之下,我认为Compass和Blueprint也在某种形式的开源许可证下)。分叉,玩得开心:D