futuremint

futuremint

Dave Woodward  //  Father and Programming Language Enthusiast. Has a love/hate relationship with computers. Insufferable iconoclast in almost all walks of life. Prefers dynamic languages with s-expressions and unpretentious technology. However, still prefers small words. And irony.

Apr 16, 2010 / 10:43am

Caching in Seaside vs. Rails

This one will be short as I stopped programming momentarily to write this.

One more reason (of many) I enjoy developing with Seaside vs. Rails is that caching is much easier and is "built-in" in a Smalltalk environment. This difference is primarily from the way Rails is structured. When a request comes in to Rails, the Dispatcher initializes new instances of your controller which then pulls in models from the DB, which also get instantiated in memory, and when the request is over this is all thrown away to start over again in the next request/response cycle.

Because of the image-based nature of Smalltalk, your model instances are always there in memory. This can change depending on your persistence strategy, but for the simple cases you usually arrange to have them in the image at all times. Sometimes they get instantiated at image start-up, other times on-demand (but this is slow, just like Rails!). Incidentally this makes Seaside much faster for the same relative level of optimization work because it skips ActiveRecord's step of instantiating your model objects on-demand. Seaside's rendering times are faster out of the box because your object instances are already there in memory ready to go.

Anyway... my point is that I needed some simple caching of a method's results to help a page load a little faster in Seaside. All I did was add a new instance variable to my model instance that lazy-loaded the result of the calculation. I then added a few more places where this "cache" gets invalidated from other method calls, and I'm done.

I didn't have to install gems, configure a new server like memcache, read docs on a gem's interface to memcache, etc. I simply leveraged the tools available in Smalltalk, and built a simple thing that just works. I don't have to worry about persisting it as its lazy-loaded. Which really is how memcache is usually used with Rails, as a place to temporarily store the results of an expensive computation.

There is nothing stopping one from doing this same thing in Rails, but it doesn't go with-the-grain of the way Rails is built and you are expected to use it. Rails is "opinionated software" after all, and I've worked on many Rails projects where one piece or another has to violate the opinions and work on it becomes painful.

For whatever reason solutions in Smalltalk end up much simpler and therefore lend themselves to easy extension and expansion.

Filed under  //  Rails   Ruby   Seaside   Smalltalk   Web Development  

Comments (0)

Jan 1, 2010 / 1:15pm

Smalltalk (and Seaside) versus Ruby (and Rails): Intro

I've been using Rails since 2004, and some of its' libraries before that (I setup a local Instiki that, AFAIK, is still running at my old employer). Once I started using Rails at my then job at a radio station group (designing/managing the websites), I decided that Rails was a superior development experience. So I started looking for a way to use Rails as a full-time job. I've since enjoyed most of the long hours I've spent developing various things with Rails for various companies.

My current full-time job still includes maintaining a Rails application (one that I built in late 2005 on a contract), and I still enjoy it. I get to make the technology choices at my current company, so in early summer of 2009 I was tasked with separating some functionality of the existing Rails app out into a stand-alone application. I initially wanted to go the route of some sort of NoSQL database with a JS only (or mostly JS) front-end (some sort of combination of CouchDB, Rails & jQuery).

However, I've also had my eye on Smalltalk ever since hearing about it from a co-worker in 2004 (around the same time I discovered Rails). I did some investigation and spent some late nights with a few quality online tutorials. I started with "Seaside Tutorial" , as well as "Learning Web Development with Seaside". Now there is the much more detailed and up-to-date book "Dynamic Web Development with Seaside". Anyway, I basically learned Smalltalk and Seaside at the same time, and decided to build the new app in Seaside.

So now almost a year later I much prefer developing with Smalltalk & Seaside than Ruby & Ruby on Rails. I use Pharo Smalltalk exclusively for development and the server deployment (I used Squeak 3.10 until Pharo went beta). The database I use is SandstoneDB from Ramon Leon, which is basically an Object Database that just persists the objects as text files (it's essentially Prevayler with an Active Record style API). Once this app needs to scale, I'll probably move it to Gemstone/S (the people behind Maglev for you Ruby folks).  For business applications, I'm currently of the opinion that nothing beats a web application in a dynamic language on top of an object database.

I still switch back and forth between Smalltalk and Ruby, and will be doing so for the foreseeable future. Most days I'm using both, sometimes inside the same hour! 

I'll be giving a talk about Seaside & Smalltalk at the February Indy.rb meetup. The similarities between Smalltalk and Ruby are pretty interesting, and now I know what people mean when they say that "Smalltalk isn't dead, it survives in most languages used today!" You can find language features inspired by, or stolen from Smalltalk in Java, Ruby, Javascript and many other languages in common use today.

I already have 3 posts I'm ready to write comparing the two languages and frameworks from a development perspective, so expect to see those over the coming months. I also have some thoughts I'm going to share about development environments. I used to be completely anti-IDE. I used to only use TextMate to edit my code, and the command line for all of the tools. Then I moved to GNU Emacs and loved it. Now I get frustrated and bogged-down in a text-editor only setup. I use RubyMine for Rails work, and Smalltalk has awesome development tools (even in the "under-developed" open source versions). The modern IDE has its roots in Smalltalk and Lisp, and once you use an IDE that actually IS "integrated" as the acronym suggests, you will never turn back.

Filed under  //  Rails   Ruby   Seaside   Smalltalk   Web Development  

Comments (6)