Cells: Components for Rails 2.3
Cells "brings the benefits of component-oriented development to the Ruby on Rails web application platform", letting you create independent and reusable components that are self contained and can be combined and reused with other cells in your applications.
InfoQ already covered Cells over a year ago, in the meantime, Cells 1.0 has been released and the work on Apotomo has continued.
InfoQ chatted with Nick Sutterer, the main developer of Cells. What changes have you made to Cells in the past year since our last interview?
A bunch of! As Cells grew with Rails from 1.2.3 to version 2.3, I learned Ruby! My better understanding of the language and various forks to steal from resulted in a cleaner and more structured Cells code.
Beside readable code we introduced a simple caching similar to the fragment caching found in Rails views. It allows Cell views to be cached until an attached versioning method decides to expire it, without loosing the object-oriented features of a Cell instance. A great help was Michał Łomnicki, who came up with patches and real test cases in his project.
From a user's perspective Cells became even faster. I recently increased view lookup speed by 99% with a stupid memoize pattern. Behind the scenes more things are going on. After spending my daytime for a project in an uncomfortable, loud office, I kept working on Apotomo, which is based on Cells and brings stateful components to Rails. That night-time coding was like a salvation from my tiresome project.
You said the last time that there's a "noteable interest" in the Rails community. How is the situation today?
I wouldn't talk about statistics here, would I? Well, when I started Cells, a handful of programmers shared the problem with Rails' lack of components with me, now there's a real «scene» of widget freaks.
Looking at the github watchers for Cells speaks for itself. We currently got something around 150 coders who want to get informed instantaniously about changes to Cells. That's cool, and I love the fact people are interested in this project. We had about 6 successful merges of forks back to the Cells mainline.
Suddenly there were blog posts popping up in the net, discussing Cells and alternatives like partials with presenters, it's exciting to read about ideas from other people.
Another indicator for «interest» is the #cells IRC channel. Everytime I join already 4-8 people are lurking around there, from all over the world. New people keep coming and ask for support or help. I think the channel is the most important support medium for the project, and it's fun to meet people there.
Since Cells was born a dozen of companies contacted me telling me about their usage of Cells in real projects, so there are people using it. Hey, even IBM kicked in, but I'm still desperately waiting for donations. Thanks to the MIT license.
A highlight for the project was the talk together with my bro Mike Pence at the RubyConf 2008 in Orlando, Florida. We had a great time hanging out in Sarasota, preparing the talk ,drinking beer and then, showtime! There were real people, sitting in the audience and listening to our talk. We had some intense discussions after the talk, and even at the pool party at night I couldn't stop babbling about components with Kirk.
Soon after my US trip we released Cells for Rails 2.3, the official announcement on the Apotomo blog got tweeted by DHH himself and brought up to 500 readers per day. That was an interesting experience and really demonstrated David's range. Wow.
David once contacted us but we never came up with a solution on how to integrate Cells into Rails. We all like it better as a plugin. Plugins are a good thing.
I'm peeking at the Rails 3 code every once in a while. I'm a great fan of Yehuda's refactorings and I really hope the new internal API will open the way for something like Cells. Everybody needs components. So right now, I either have to wait till the Rails 3 API gets solid, or I could dive into the new code. Right now, I'm concentrating on writing tutorials, articles and improving Apotomo, we will see if the core guys come up with a Cells replacement in Rails 3.
Do we really need stateful components?
No. If you prefer the "brutal linear controlflow" where you either render the complete page at every request, or have some cluttered AJAX-logic in controller, view and maybe even in the model layer of your MVC-stack, then you don't need components. Same thing, if you like to establish the complete process environment at every request, you won't need statefulness.
Let me quote Mike. "It's time to have better toys, the cool kids have it already, so why not take Rails to a further level?". Smalltalkers love Seaside, GUI developers hate the web. Why not take the best from both worlds and put it on Rails?
I mean, it's up to the programmer how much Apotomo he wants in his app, and as soon as he experiences the real power of stateful widgets, he will never return to his fat controllers.
It's not only the reusability of his components, it's the better encapsulation, strong test scenarios for small parts of the apps, it's the event-driven approach, less code and a better development workflow that will convince him that stateful, living widgets are... cool.
To find out more about Cells, visit the Cells website on RubyForge.
Srini Penchikala Aug 21, 2014