In the beginning there was PHP then God created Rails
So another blog on the web singing the praises of Rails. Not the most innovative subject, but a personal one non the less.
So I have started to mess around with Ruby on Rails. Is this me jumping on the band wagon? Yes and no.
It is true that Rails is very in vogue at the moment and sometimes it seems that if a web app is implemented in Rails its cool, hip and trendy and heralds the dawning of a new revolution in web technology. Whereas if the same app had been written in Perl I doubt it would have attracted all the plaudits.
On the other had rails does offer a number of advantages over, say PHP. Now I am not comparing Rails with PHP and I am not getting into the language V framework debate (See the flaming Nathaniel Brown got). All I will say is that Rails serves as a domain specific language derived from Ruby for developing web applications. The real language debate is between PHP and Ruby. I would go as far in saying that in terms of web applications they are both equally as capable as each other, the advantage of Rails is its concise neatness.

I have written a few very small sites in PHP with MySQL and by the end it was all a real mess. Looking back it seems more a case of hacking scripts rather that developing an application. PHP here, HTML there, SQL everywhere. Doubtless that the majority of this was based on my limited knowledge of the language or the domain and with a little more foresight and planning the situation could have been greatly improved.
However at the time, and with out knowing any better I liked the simplicity of getting things done with PHP. A total novice (me) could get up and running quite quickly (after the epic struggle of getting Apache, PHP and MySql to work together on Windows) and crete (dirty, slow) data driven sites quickly. This was largely helped by the community around the language, so help was always at hand and hundreds of online tutorials provided loads of guidance.
What I wanted however was more structure to my code and so I looked around at the available frameworks for PHP and tried in-vain to use one. After a number of hours or perhaps days I gave up trying to get the large number of PEAR extensions needed to work on my development machine and resigned myself to the fact that even if I got it working locally the chances that my web host would have all the required pre-requisites were slim.
Then I went to a presentation by Amazon.com.
The main topic of the talk was the history of Amazon.com in technology terms, presented to a bunch of Computer Science students. All very interesting, but the thing I remember most happened in the questions afterwards. In responding to the question of “What language is Amazon written in?”. The speaker listed a number of various programming languages with the predominate web stuff being implemented in Java. The speaker then made a small comment to his assistant along the lines of “but seeing some of the stuff you can do in Ruby on Rails I am open to suggestions of different approaches”. So, what was this “Ruby on Rails” he was talking about? I had come across Ruby about two years previously and had not given it much time as I was supposed to be learning Ada. As some of you may know everything seems more interesting than Ada when you have to learn it.
Anyway, after the talk I looked into Rails in a bit more depth and it seemed to answer all my problems. It provided me with a framework that forces you to use the Model, View, Controller architectural pattern in your applications design, and it was all in the box, not hundreds of messy extensions to install in order to get it working.

Credit: James Duncan Davidson/O’Reilly Media, Inc.
So I download and installed it following the now famous Dan Benjamin tutorial and together with the ubiquitous Agile Web Development with Rails at my side began to play. One Depot application later and I realized that it was a whole lot more than just a file stricture.

This marked my 2001 monolith moment.
So to get going I am building a blog with a CMS. groan I hear you say and you are correct because does the world really need another blog CMS system? Well no!, mine will be worse than probably all of the others available, with inefficient code, poor design and bugs a plenty, but it is a great way to get familiar with Rails and the best way to lean is to do.
So I have rambled on for a what seems like ages and this is what I wanted to say all along. I prefer rails to PHP because it makes the application so much easer to maintain and write all in one language. I have been writing the CMS part of my blog for a couple of weeks now and I have not had to write one line of SQL, not a query to be seen. It is all wrapped in Ruby code by Rails. A query to get all tuples in a table is as simple as:
something.find(:all)
As opposed to:
SELECT * FROM something
The same goes for your database schema and javascript. Rails provides a Domain specific language for each part of the web app, but each language is derived from Ruby so you need only trouble yourself with one language instead of loads.
All of this goes to make Rails a really great tool. It makes web development feel more like native application development, rather than the mess of code, markup and queries I remember.
And believe me there is sooooooo much more to rave about, but I will not bore you any longer, just give it a go.
No Comments Yet