Ruby on Rails
February 20th, 2005
One of my 2005 new year’s resolutions was to tinker around more with open source software. Well, already 2 months on into the year and I’m glad to say that I’ve gotten over my procrastinating ways to start to come good with my promise. Over the past few weeks I’ve installed Apache, MySql, PHP and WordPress to get my blog up and running.
I original tried using Moveable Type as my blogging engine, but got frustrated and gave up (after 5 hours) when I couldn’t get Perl and PostgreSQL 8.0 to play nicely. You can of course use a variety of data providers for Moveable type, but I stubbornly wanted to use the first Win32 native release of Postgre. It was all or nothing.
Next stop on my open source voyage is Linux Town. I’ve had flirtations with Linux in the past, but my encounters were brief because I couldn’t motivate myself to do anything on it that would keep my attention. Also I’ve been spoiled for several years now by .NET, which I consider to be the total package in terms of application development, and has kept me tied mainly to Windows.
So how is this next Linux encounter going to be any different? Firstly I’m going to be using Fedora core 3 running within MS Virtual PC. This removes the hassles associated with running multiple OS’s like dual booting and such, and allows me to switch back and forth with ease while going about my usual XP duties. Next, to force a dependency of sorts and to prevent my Linux usage from going astray, I’ll be using it to host my blog.
I have no intention to abandon windows as a result of all this open source experimentation. It’s served me well since W2K and through sensible usage - things just work, with little fuss. I consider myself a pragmatic computer user who doesn’t get fanatical enough to take any sort of allegiances but rather prefer to value software on its merits.
I think the open source movement is driven by a lot of smart, innovative and devoted developers who want to make a difference and keep the big players on their toes. I want to get acquainted with the various established and developing projects in the open source world as recognition of all the good that’s going on in this area and to be able to respect myself more as geek.
Another driving force that has compelled me to venture into open source territory has been the buzz surrounding the Ruby programming language and the associated Rails web development framework. I haven’t even begun to scratch the surface on this stuff yet, but I have started to play a little.
I followed this good tutorial as my first foray into Ruby. It provides instructions on setting up Ruby, the Rails framework, MySQL and code for a simple recipe management web app. There’s plenty of good documentation out there to help you setup Ruby on Rails on various platforms. The process itself is relatively smooth and trouble free.
Ruby on Rails - First Impressions
I think Rails will have the same affect on open source web developers (who predominatantly code in PHP) as .net had on asp developers. When asp.net came around classic asp developers were liberated from writing spaghetti code through an object oriented framework that promoted the separation of logic and UI. Also at their disposal were a rich set of web controls and data binding mechanisms to free them of mundane coding duties to focus on the bigger picture. But to take advantage of these new features required a major change in programming mindset which was more challenging for developers not experienced in OO programming.
Rails offers an object oriented framework that enforces tiered design and good programming practices. There’s an air of elegance about it from the organised application directory structure to keeping url querystrings look tidy.
You create a Rails application by first running a utility script in the location you want the application to reside. The script creates a directory structure containing levels for the various application tiers, configuration setting, log files and a bunch of others which I don’t know the exact nature of yet.
A striking feature of Rails which I got to see in action from the tutorial is the ability to interface with a database using minimal code. With as little 10 lines I had all the code necessary to display web pages for add, edit, delete and list functionality on a table of recipes. This was firstly achieved by running another utility script that created all the scaffolding needed for CRUD operations on the specified database table.
The tutorial goes on further to facilitate table relationships (e.g. categories of recipes), and customising the display of the pages. The speed and simplicity of development gained by trivialising mundane tasks such as db CRUD operations is a big selling point for Rails. Of course, you could trivialise these tasks somewhat in other environments like .net for example by using tools that generate CRUD and strongly typed collection templates based on the database entity you want to create a data layer for. I use CodeSmith exactly for this purpose. In .net I initially had to manually create these templates, which required me to have an understanding of the internals of the process and allowed me to have complete control over the implementation. Rails goes one step further by freeing you of this process, although I think you can modify the scaffolding as needed. This is yet another thing I have to investigate.
ASP.NET is still my development framework of choice but Ruby on Rails has left a good enough impression to warrant further investigation, and then there’s the Ruby programming language itself which I hope to comment on more in future posts.
Posted in Uncategorized | Comments Off