The blog of Tobin

Tobins nerd blog on .NET, Software, Tech and Nice Shiny Gadgets.

Tuesday, March 22, 2005

Ruby On Rails - random thoughts from a .NET perspective - Part 1

I recently started playing with Ruby On Rails (www.rubyonrails.org). What can I say, so far I think it's beautiful! Hehe, I don't say such things very often, but the darn thing just seem so simple! And, every time I want to do something, I find the perfect solution.

In case you haven't heard, RubyOnRails is a web framework that offers a very quick route for implementing web applications. If you have heard of Deklarit for .NET then Rails is similar in that it offers tools to assist in n-tier development from data source to business object to GUI.

And, in case you haven't heard of Ruby, Ruby is a fairly new language which has borrowed the nice bits from a myriad of other languages, and then added a few nice things itself. It's known to be highly expressive, simple and powerful.

This has all been a new adventure for me since I spend most of my day in Visual Studio .NET. I've grown to love .NET (and c# in particular), but seeing new tools and languages is certainly a good thing to do in my book. I'd recommend it to anyone if you get the chance, just to give yourself a new perspective. If you don't believe me, check out The Medici Effect, which talks alot about giving yourself new perspectives in life! The author, Frans Johansson, even understands the brilliance of swedish pizza 8-)

Once I've finished a project in rails, I'll probably write about how it compares to my own .NET experiences. To give you a taster of why I'm buzzing about Rails, consider the following things I've found out (I've only been using it for 4 days!).

I'm not slagging off .NET by the way, I'm just excited by finding a new "toy"! I'm looking foward to taking my experiences of Rails back into my .NET work. This is NOT a comparison of which tool is best, I'm just rambling about Rails from the point of view of someone who does a lot of .NET coding.

Object Persistance

It has built in object persistence using the ActiveRecord pattern (see www.martinfowler.com ). I can do something nice like this to load some customers:

customers = Customers.find_all ["where company_name like ? and date_created > ?",'SoftNet.com','01-Mar-2005']

customers.each{ customer
customer.destroy unless customer.is_nice?
}



Once nice thing about Rails is that it gives you a great deal for free. For example, see the is_nice field on the customer class? Well, I didn't code that. That got added at runtime because there is a column in my database by the same name. Because Ruby is dynamic it can do stuff like that. I was initially worried about rails being too constrining by having a lot of "conventions", but there always seems to be ways around these if you need it.

I've used NHibernate quite a lot for .NET, which is an amazing tool I think. The ActiveRecord approach that Rails offers *is* simpler IMHO, but less flexible and may not appeal to those who want true independence between object model and database schema. The benefits that rails gives me is that I don't have to set up any mapping files, and I can still do inheritance and components, which is nice. I seiously doubt it's as flexible as good ol NHibernate, but then again I can map that Customer class in 3 lines of Rails code:



def class Customer < ActiveRecord::Base
has_many: orders
end



Another thing I like about ActiveRecord is that it is in keeping with the DDD concept of Ubiquotous language - since the language of the database and the source code are constantly synchronised.

Model-View-Controller (MVC)
When you look at a rails application, you'll instantly see evidence of MVC going on. Folder names such as "controllers" and "models" and "views" kind of give it away. Model View Controller is a well known framework for cleanly coding stuff. It basically allows us to separate concerns. Ever heard someone say "Your business classes shouldn't talk to your web pages", well, MVC provides a way of separating things to achieve such rules. Lol, I shouldn't even try to explain this stuff, if you google the term you can find out why it's good. Anyway, Rails gives us a neat toolkit for defining model elements (business classes), views upon those elements (web pages), and controllers that handle requests and perform actions. It's all very clean, structured and methodical I think!

It looks like someone wants to bring this into the .NET world - since there is already a CastleOnRails.NET project.

Page Layout
Rails comes with a really nice set of layout libraries that allow you to make sites with minimal duplication. Have you heard of MasterPages for .NET (I mean the external .NET 1.1 components that MS will be building into 2.0)? Well, Rails has simple some tools that give similar functionality. Check out Layouts and Partials if your interested. The main thing that I liked about these is just how easy it was to get going with them.

Ajax
Ajax is a big buzzword that I keep hearing but don't know much about. You may have heard the hype about googles intelligent search box that can tell you how many matches there are for the word your typing? Well, that's an example of the Ajax philosophy in action. From what I can see, Rails is seriously trying to make this stuff easy for the developer in building web applications in this way. Read about the 0.11 release of Rails to get a feel for what's going on in this area.

Ok, my fingers are tired now. Was that at all interesting!? Lol, I'll hopefully write some more after I've spent a bit more time in Rails. Any comments welcome!

Desperate students request quote for homework

As a freelancer I use agencies such as guru.com to find new projects. These tend to bring me a steady stream of project invitations of all kinds. Lol, and then today I got an especially interesting one that started with...

"Description
------------------------------
Pointers and dynamic memory space allocation
Strings and string functions
Multi-dimensional arrays
Arrays of pointers
More control structures
Sorting
Functions, parameter passing, side effects
Modular design


Now that Spring Break is almost here, you are getting very specific with your vacation choices. You are ready to create and print up possible itineraries of your vacation plans. You are going to be using the same type of data as for the previous lab with some additional information to be input and different types of output. You will be accepting data for 3 to 5 vacations.

First you will be taking in the same data as in the first lab but instead of storing it in six separate arrays you will store it in one multi-dimensional array that can hold all six types of values (note that this means that all the data must be stored as the same type of numbers.) You comments should indicate which dimension of the array represents which piece of data... "

It goes on for about another page, but you get the idea. They had basically cut and paste their entire university assignment description, and asked me to bid. Lol. I've seen students post assignments on newsgroups, but never on a commercial project bidding site.

The most facinating things about all this is that they're willing to pay between $41 and $60 per hour! Of course, I didn't bid. It's very sad though, whoever posted this should drop the course and find something they're interested in. Even better, their tutors will probably instantly detect something fishy about their assignment, and boot them off the course!