I know Kung Fu

June 17th, 2006 by Ivo

This week I visited the Holland Open Software Conference. It was a nice conference, I will write a review later.

What I want to talk about now though, is what happened to me during this trip.

Before I begin, you should know that I am a die hard PHP fan, and I have been using PHP for 6.5 years now. If there is one thing that I've learned during this time, it's that PHP rules.

For a few months now however, friend and colleague Peter has been nagging me to check out Ruby. While I have been working mostly in PHP, he has used Ruby for the backend of epointment.com. I had looked at his code before, but it didn't catch on. It eyed weird, had funny-looking constructs (Ruby's lack of braces reminded me of Visual Basic even) and it was surrounded by a lot of hype, which often is a bad sign. It didn't even have a '++' operator. Get real.

Then he gave me this book they call the 'Pickaxe'. I tossed it on my desk, near the rest of the things-to-do-which-never-get-done.

But now I was going to this conference, which was a 2.5 hour train trip on both conference days, so I decided to check out the book to kill time while on the train.

The first day I read about 30 pages into the book, and I was intrigued. I read about how everything is an object, how even primitive types are objects. I read about code blocks (which turned out to be the funny constructs I didn't understand when reading Peter's code earlier), about the ability to redefine operators (which I remember from C++), about its regular expression support and about how Ruby encourages application of OO principles like encapsulation and loose coupling.

I had my laptop with me but no Ruby installed, so I wasn't able to try any of the code, but I was intrigued nevertheless.

At night, I decided to install Ruby so the next day I was able to actually hack away a bit. I read more in the book. I delved into collections, found out how they handle looping and how iterators are an intrinsic feature of the language. Around 100 pages into the book, I was hooked. I was writing classes, trying out all these language features, and it was great fun. I hadn't read nearly all of it yet, but at one point, I needed to get something done in my code, and without looking it up in the book, I just typed what I thought was the right way. I thought 'oh well, let's see what this does' and ran the script; and it simply worked. It didn't even generate a parse error. It was handled exactly the way I had expected it. This happened on 2 more occasions. So Ruby seems to be quite intuitive; if you have an idea of how the language is set up, what its approach to object orientation is, you can almost guess how you should accomplish things. So there I was, enjoying a new language. It felt like the first time I used PHP, back in 1999. Ik was astounded with the ease with which you could write programs (something which I never felt with C, C++ or Java).

I nearly missed my stop, and when I bagged my stuff and stepped out of the train onto a sun-engulfed platform, one thought crossed my mind.

"Whoa, I know Kung Fu".

It really felt like that. It was as if in a few hours, a whole new approach to programming was uploaded into my brain. In essence it was just a new scripting language I had just learned, but it merged perfectly with everything I ever learned about object oriented programming. I realised why they call it 'Ruby'. It is this clean language that has a pragmatic approach to object orientation that I haven't encountered before in any language.

And then, during the short walk from the station to the conference premises, I was reflecting on what had just happened. In my mind I was already looking at how I could do certain features of ATK more cleanly in Ruby. I was comparing how things are done in PHP and how the same things are done in Ruby. I marvelled at how Ruby fits ATK's "less code" philosophy.

And then I got scared.

What if I can't find any aspect of PHP that is better than Ruby? What if the only reason to still use PHP is 'that it is more widely used'? Surely that will not be the case, right? I have been using PHP for 6.5 years and it has never let me down. I am not crazy, am I? Ruby seems to be this shiny apple, but will eternal damnation come my way if I eat it? is Ruby the Red Pill? Will this be the beginning of the end? Will I switch from PHP to Ruby? This question has been bothering me since I got back from the conference.

After a good night of sleep, I've concluded that I will use both. PHP feels like this jeans that I have been wearing for years. It's worn out, but it's still my favorite jeans. It just has the right fit. I have other newer jeans that are less worn, but they still are not as comfortable as my old one. Although this Ruby jeans feels damn comfy, too.

But my jeans are not mutually exclusive. Neither are Ruby and PHP. So I'm going to use both. I'll use PHP here, and Ruby there. Let's just see what the future will bring. I will consider making a Ruby version of ATK (on top of the Rails framework), so I have two options when developing web applications. I hope to continue to be part of the PHP community for a long time, and I hope I will become part of the Ruby community too. Surely they'll accept me even if I still use PHP a lot.

In any case, one thing this tale has left me with is a deeper resolve for object orientation. I hope that for PHP 6 and 7, they will look more to their sister Ruby than to their predecessors Java and C++. Because Ruby knows how object oriented programming should, and can, be done.

14 Responses to “I know Kung Fu”

  1. June 17, 2006 at 11:53 am, Tri Pham said:

    They same thing happened to me, but with a little twist. I’m also a hardcore PHP developer back from the days of PHP3. A few months ago I reviewed Rails and I was not impressed, mainly because I hated the Ruby syntax. It’s so much different when you’re accustomed to C-like languages. Few months later I gave Rails another try and suddenly I got in love with Rails and Ruby. I got to know Ruby better and now I do understand the philosophy behind the language. And yes, it’s very clean and very logical. More than C-like languages.
    So my time is lately more devoted to Ruby and Rails, but PHP is still my brother because my web applications are still developed with PHP. However, I do see myself in the (near?) future to become a devoted Ruby on Rails developer and leave PHP behind.

  2. June 17, 2006 at 5:47 pm, Matt said:

    Language feature comparisons are for personal tastes and the art, and rarely show great leaps in productivity on one side or the other unless you’re comparing the fundamentals like memory management, dynamic versus static, compiled versus interpreted, etc.

    So when you’re comparing languages in the same major feature scope, it’s all about appreciation of the art, not about picking the language that will get you to the target better or faster. So that leaves you with the question of what’s more important for your project: appreciation of the art, or broader business concerns?

    Often that means that PHP is going to be the right answer simply because it’s the standard. Apache is everywhere and PHP is everywhere, they’ve been working as an integrated team for a long time now, and the alternatives don’t provide any great productivity, maintainability, stability, or performance leaps.

    That said, as Ruby continues to gain a stronger foothold in the web application world its business viability is only going to grow. Maybe it’s the beginning of the (long, drawn out) end for PHP. Maybe not. Time will tell.

  3. June 17, 2006 at 10:17 pm, DerelictMan said:

    Ruby is definitely the red pill. As for Matt’s comment:

    “You have to understand, most of these people are not ready to be unplugged. And many of them are so inert, so hopelessly dependant on the system, that they will fight to protect it. ”
    :) (Just a joke)

  4. June 18, 2006 at 7:30 am, AJIT DIXIT said:

    May I request you to look at rails
    If you create ATK philosophy plugins for rails it will be a killer application
    Power Of Rails + ATK approach just funstastic

    Regards ,

    AJIT

  5. June 18, 2006 at 7:24 pm, Jaen said:

    PHP is an imperative, mostly procedural language.
    Ruby is functional (in philosophy) and object-oriented to the bottom.

    That’s quite a fundamental difference. “Same major feature scope?” Assembler and Prolog are in the same major feature scope by that metric :)

  6. June 18, 2006 at 9:54 pm, Matt said:

    PHP provides enough OO for that distinction to be irrelevant in terms of productivity and maintainability. As I said, it’s a difference that changes the appreciation of the art but not the business decision.

  7. June 18, 2006 at 11:04 pm, Jaen said:

    (note that the blog post didn’t say absolutely anything about ‘business’, and neither did I)

  8. June 18, 2006 at 11:12 pm, Matt said:

    Which is why I have been repeatedly mentioning “appreciation of the art”. I believe I was clear about the context of my observations and of “major feature scope” in my first comment.

  9. June 18, 2006 at 11:14 pm, Jaen said:

    (also note that the blog post made no sweeping generalizations like “alternatives provide no productivity, maintainability etc. benefits”, without offering a single shred of evidence)

  10. June 18, 2006 at 11:22 pm, Matt said:

    If you reread my original comment, you’ll hopefully note that I am adding additional observations beyond what the original article provided.

    If you want evidence of maintainability, productivity, and other concerns, then that’s something beyond the scope of this discussion thread. On my own part, I base those conclusions on experience with different language features over my time as a programmer, and I have found it best to categorise them broadly into two sets: 1. appreciation of the art, and 2. business concerns. Sharing that observation was the intent of my original comment.

  11. June 18, 2006 at 11:27 pm, Jaen said:

    Thank you for sharing that observation.

  12. July 03, 2006 at 4:33 am, colson said:

    I too and a PHPer and I’ve picked around with Ruby a bit. I have no practical purpose for really switching at this point other than it would be a nice language to know.

    I think with most languages you just carry on with whatever you prefer. Rails offers some nice additions to Ruby and for what Rails is, you can also use cakephp [url]http://www.cakephp.org[/url]. So I think alot of the “this better than that” talk comes down to preference and what makes most sense at the time you need to address a given situation. At first, I was a bandwagon hopper but at the same time, it’s just another language and if I really want something that is “far-out” there, I’ll go with io – even simpler than ruby and still taking more time to wrap my head around.

    [url]http://iolanguage.com[/url]

  13. December 31, 2007 at 1:24 am, jansch.nl » Blog Archive » PHP in 2007: Serious Business said:

    [...] say that Ruby was a big threat to PHP in 2007 (thanks to the Ruby on Rails framework). I have flirted a bit with Ruby myself, and language-wise, it’s much cleaner and consistent. However, selecting a [...]

  14. May 26, 2008 at 6:44 pm, Ivo's Blog - jansch.nl » Blog Archive » php|tek 2008: day 3 and wrap up said:

    [...] was nice to hear Terry talk about the ‘kung fu’ experience that most first-time ruby users have. I had that Kung Fu experience once, but while I said back then that I would start to use Ruby, 2 years later I still haven’t. [...]