h3. What is an abstraction layer?
An example: *Every kind of _framework_ is an abstraction layer.* It saves you from working with concrete code by providing _higher-level_ methods and concepts. Ruby abstracts assembler, Rails abstracts working on HTTP-based applications, ActiveRecord abstracts SQL, and so on.
h3. What’s your problem?
The funny thing is, basically I agree (again!) with dhh and his followers: *I like abstraction layers*. To be precise, I especially like abstraction layers if
* they are *horizontal _layers_*, meaning they are *clearly separated modules* and not hard-wired in the core like @RJS@. @ActiveRecord@ in Rails 3 is a good example of a cleanly encapsulated abstraction layer.
* they are *_optional_*. Rails has opinionated the process of developing web apps for years (ORMs, “monolithic controller/view architecture”:http://nicksda.apotomo.de/2010/11/rails-misapprehensions-cells-dont-break-mvc/, “pseudo-REST”:http://nicksda.apotomo.de/2010/10/rails-misapprehensions-crud-is-not-rest/). People are used to it and want soft transitions (well, actually this is _not_ my very opinion, whatever).
* they are *vertical _layers_* in a sense of splitting one monolithic app into several manageable component applications. This is also an abstraction layer and completely ignored in Rails.
h3. Have more abstraction layers!
Rails is a web framework and does a pretty good job at it. It gives you PHP-like templating, a great ORM and the @FrontController@ pattern. Now this is Rails status quo.
*Abstraction layers must be separate gems* with adapter modules for Rails. Rails itself needs an architecture towards this, and Rails 3 already is a great step in this direction.
Abstraction layers should also try to be separate layers and not mix in stuff randomly into M, V, and C at once.
If you hard-wire “abstraction layers” into the core, *they are no _layers_ anymore*. This is my problem with the “current implementation of RESTful representations”:http://nicksda.apotomo.de/2011/04/rails-misapprehensions-the-hardest-thing-about-rest-is-working-with-representations/ in Rails. Another example where more work is needed is the view layer. The “cells gem helps having object-oriented views”:https://github.com/apotonick/cells by _abstracting_ stupid partials and helpers to view components.
h3. Too much abstraction means Java!
Don’t get me wrong here. *I do not evangelize useless abstraction.* That’s why I say “_Make it optional!_” If you have lot of JS, use “coffeescript”:http://jashkenas.github.com/coffee-script/. If you have RIA frontends or portals in Rails, use “Cells”:http://github.com/apotonick/cells or “Apotomo”:http://apotomo.de/. If your CSS is bloated, use “Compass”:http://compass-style.org/, and so on.
*But please keep the Rails core an _abstract_ core.*
Now, please stop the comment spamming on github and spam me instead.
7 thoughts on “Rails Misapprehensions: Rails needs more abstraction layers!”
+1 Awesome post 🙂
+1 awesome post
But maybe you could clarify, for the confused, that Coffeescript is a valid abstraction layer for those who chose it, and it’s not a big deal. Reading this it ins’t clear cos of mixed sentiments.
It’s really good concept about separation abstract layers in gems when it’s up to you what you really wanna use in project. But, I think that Rails core team treats Rails as a fully-prepared-to-work product so they wanna put all that stuff as default.
Actually it’s a really good thing for the beginners, they don’t have to look for an external gems, perhaps they don’t know any except rails 😉 I’m receiving this like a marketing trick, using external technologies to show how cool is writing in Rails =]
I don’t get what you are talking about Nick, flame war on github was superb:) The trolling was definately a art in that case:D
Although the lazy part of me would prefer haml and sass (not scss) as default as well, it’s so easy to change the defaults it doesn’t matter that much.
It won’t make bad programmers write good code (only less:). If you were dropping your jQuery all over the place before, you will still do that with less characters in coffeescript:)
But that IMHO shouldn’t worry you as a consultant who is rescuing legacy apps:)
Just fyi.. Coffeescript is not an abstraction layer…
Is it possible to create a single representation from multiple models?