Archive for the ‘Rails Programming’ Category

Experiencing Rails: musings of a formerly gung-ho PHP programmer, Part 1

I used to live and breathe PHP. I developed many sites in PHP over the years. I ended up maintaining a popular PHP-based Ajax library and even wrote my own PHP 5 MVC-style framework. Life was good.

I loved PHP. I found all those Ruby on Rails people to be annoying. I didn’t want to learn a new language. Ruby looked rather odd to me. I’d done a bit of work in Python and wasn’t super thrilled with it. Why would Ruby be so much better?

But then the Zend Framework project was announced at the end of 2005, which sucked the wind out of the fragmented third-party framework market, and I realized that I was putting a lot of effort into writing a lot of code that was probably not going to be used by anyone other than me. Did I really want to go that direction? I played around with Zend’s early code as they released it, but it just didn’t grab me. Now I know it’s quite possible to build an awesome site with ZF; I just felt like I needed a change. It seemed like Zend was recreating some of the work that had gone on through the PEAR project. Why was the developer community so scattered? If I was going to dump my framework and hop onboard a new one, I needed to feel confident and excited about its future as both a technology and a tribe.

I decided to swallow my prejudices and take a fresh look at Rails. I got it set up on my Mac, looked at some tutorials, and began to mess around. Once I got the hang of the funky Ruby syntax, and wrapped my head around some of the more in-depth concepts of the Rails framework, I began to enjoy writing code. I mean, really enjoy writing code. Programming wasn’t just a means to an end, but something that felt — dare I say it — fun. There were a few things I missed from my own framework, but Rails strikes a very interesting balance between rigid conformity and wild west hackery. You can make it do some clever things if you put your mind to it.

The thing I like most about Ruby on Rails, coming from the PHP world, is that it is non-linear. What I mean by that is that Ruby is a fully object-oriented language with functional programming constructs. PHP is a procedural language with OO tacked on. Programming in PHP tends to follow a linear paradigm — you do A, and then you do B, and then you do C, and you pass the necessary data around as you progress. Ruby is different — you tend to program from large problem to small problem in shrinking concentric circles, and the nature of specific data manipulation scenarios directly dictates the flow of execution. Instead of doing A, B, and C, you describe how X, Y, and Z are constructed, and then tell them to act upon their constraints. I know that sounds rather vague, but trust me, it’s a very different way of thinking.

I will expound upon this more in future posts. Suffice it to say, I love Rails now and can’t imagine wanting to switch to another language or framework again. PHP is a good platform, and I’d still pick that as my #2 option. But, at this point, DHH and friends have made me a convert.

(DDH = David Heinemeier Hansson, founder of the Rails project.)