SCSS aims to address some of the repetitive elements of CSS through the use of variables, nesting, and mixins. This feels more acceptable to me than CoffeeScript, but my first encounter left me burned.
A few other abstraction libraries of relevance: Haml aims to generate HTML without the use of HTML tags. Additionally, Squeel‘s (MetaWhere 2.0) aim is to remove all SQL from your projects.
So what am I bitching about? Abstraction is a good thing right? I see two categories of abstraction. The first being the “good” kind, that allow you to be completely ignorant of the underpinnings. For example, Ruby converting down into machine code.
Development in these libraries also requires that you understand both the DSL of the library, as well as being familiar with the language of the generated code. This additional skill requirement adds time to a project, and raises the entry bar for new developers. Its difficult to be proficient at a language, and a DSL that generates that language at the same time. A Ruby developer told me yesterday that he was surprised at how rusty his knowledge of SQL had gotten. Its shocking to me that a web developer would struggle with SQL, but I think its an accurate sentiment on which many Rails developers would agree.
Another casualty of abstraction is performance. Not only is the generated code sub-optimized relative to coding it by hand, it is also being run through through more system calls to get there. You can either compile up front (CoffeeScript, SASS), or you can incur this penalty on-the-fly (Haml, Squeel).
While none of the libraries are a requirement of web development, when working on a team that uses these technologies you are expected to produce consistent code. Even though these libraries let you execute “native” code, doing so is discouraged because of the availability of the DSL. The syntax for embedding native code (if its even allowed) is often cumbersome, and loses editor functionality such as syntax highlighting and parsing.
Squeel’s not for everyone, and you’re certainly entitled to your opinion, but my aim for it isn’t just to eliminate SQL strings from Rails apps. It’s to allow us to change the way we think about query problems, when it’s convenient to do so.
Interestingly, in early tests I found that depending on what kind of stuff you’re doing, Squeel can actually be faster than stock ActiveRecord.
I’m not sure that still holds true today, but I think it has some pretty major wins in terms of code readability. I don’t really think it enables people who don’t understand SQL to do incredible things, but I do think it helps those who do avoid dropping down to a string to do something as simple as a LIKE.
See http://metautonomo.us/projects/squeel/ for details (especially the section on Predicates).
@Ernie – Thanks for responding. There are certainly benefits to using MetaWhere, however I find myself in an awkward development pattern when using it. I find that I am writing out my SQL query, then transcoding it into MetaWhere syntax. When I see a MetaWhere SQL query, I transcode it back into SQL to understand it. I find this to be the case with the other abstraction libraries as well.
I question if this is the intended pattern, since you mentioned that one of your aims is to change the way we think about query problems. Perhaps MetaWhere’s use case is in smaller pieces of SQL that can be chained together (like scopes) for an aggregate effect?
@Ben — exactly. The idea is that this allows you to maintain the individual conditions of your query in hashes, for instance, while still accessing more powerful comparison operators. You can merge to them, maintaining the nesting level to traverse multiple associations, and know that the proper table name will be resolved for your conditions.
In short, there’s a lot of value in holding onto alternate representations of your SQL syntax until the last possible second, when it needs to be sent to the database.
Sweet fancy Moses! It’s as if you actually heard some of the things I said.
Pish posh. I know, I know, a java developer saying pish posh to that shit. You know what? I still write all that shit out. You know why? I tried fucking GWT which tries to do just about everything you mentioned. It’s a piss poor substitute not to mention freeking compile times.
Anyways enjoyed reading about it 🙂