Archive for April, 2007

How I Stopped Worrying and Learned to Love Ruby

The past week was very enlightening. Reading the PickAxe books, I felt like I was going back to my Perl-learning days, with all their headaches and all their joy. I can’t believe I haven’t learned Ruby before.

In Ruby, where everything’s an Object, life is very simple: Everything descends from an Object class, and you can easily manipulate each and every object’s properties during runtime (that’s where Rails gets its magic from). This approach gives Ruby flexibility similar to Perl.

I keep bringing Perl up because it’s the first language that I learned, the first language that I “mastered”, and the language I enjoying coding in the most. The problem is my poor brain is built to compare and contrast, so I can’t help but get myself into a Perl vs. Ruby argument, especially that I’ve already done my Perl vs. PHP homework.

I admit I was turned off a little by the hype that is Rails. Granted, Rails is amazing, and 37signals’ marketing brilliantly associated Rails with Ruby. But if Rails turns out to be a fad, or it gets smeared by FUD campaigns, Ruby will be affected just the same.

However, putting popularity contests aside, Ruby’s zen-like sensation left me wondering whether I should use it for any serious projects.

My first (and most important) gripe was that Ruby’s performance suffers at least double as much as the next scripting language. The language shootout page clearly shows that Ruby sucks in most benchmarks. I’m not even going to mention Ruby vs. C or vs. Java because the score difference is so huge that Ruby doesn’t stand a chance. It could be because nobody paid attention to Ruby’s implementation, or because Matz wanted to keep the source code clean, or because Ruby doesn’t use a VM (like Python) and doesn’t have a 20-year-old hacker community (like Perl).

After much thought, I could only come to a single conclusion: It doesn’t matter! And the reason it doesn’t is because Ruby suffers not by design, but by implementation. But then again, every single language I know went through that path: Java was slow until 1.4, Python was slow until 2.3 (or so I believe), Perl was slow until 5.6, PHP was slow until 4.x, but they eventually solved those problems; after all, the rule is: Make it work, then make it fast. But In all honesty, if my problems can be solved by buying a few more server boxes, then the hell with it, I’ll use Ruby.

Second gripe was the availability of libraries. Ruby’s Gems are no where near CPAN nor JDK. There exists some very interesting stuff, but the vast majority of libraries pale in comparison to what’s available with more mature languages. Funny thing is, it doesn’t matter either. Nothing in software engineering says you can’t use other people’s work, in fact that’s why things like pipes exist: to bridge different tools together. Plus, Ruby’s mkmf utilities make it a lot easier to bind C libraries to Ruby. Now guess what, Perl, Python and PHP are all “libraries”, in a sense that the executable itself is just a wrapper around the shared object that is the language interpreter. This means we can implement Inline::Perl and Inline::Python, just like Perl’s Inline::Ruby and Inline::C.

The last gripe was Web server support. It’s not enough that Ruby is slow, its server support at the moment seems more like an experiment than a serious project. mod_ruby cracks under pressure, and it’s not nearly as flexible as mod_perl. Now now, there’s nothing to worry about, Ruby’s FastCGI performance can hold your business logic together. It’s still not the fastest, but FastCGI eliminates start up cost, and that is one expensive operation.

And that was only the surface of my internal monologue. It’s relatively easy to learn a new language, but it’s damn hard to forget about your emotional attachment to another. Programmers know this, and that’s part of why the Java community went crazy when Rails (and inherently Ruby) got all the attention.

So here’s my advice: Learn Ruby anyway, because it’s worth having a mini epiphany. But most importantly, learn to program, because at the end of the day, it’s not the language that matters, it’s those who know how to use it.

ALA Web Design Survey

I know this isn’t a design blog, but in one way or another we do relate to designers. Please take ten minutes of your time to answer the Web Design Survey.

ALA Web Design Survey

5 Reasons to Hate Ruby

5. Ruby Is Japanese For Perl

Originally created in Japan, Ruby is just a washed out Perl, an ill translation of a language if you will. There’s no $_, $`, $@, $$. There’s no m///, s###, y!!!, tr^^^, no qq, qw, qx, qr. Ruby doesn’t even have $scalars, @arrays or %hashes. How does it expect me to speak a language with nothing but, um, words?!

Though I excuse Ruby, I completely understand its reasons for being weird. It’s Japanese, it can’t use English.

4. Ruby Only Has 38 Keywords

According to Learning Ruby, there’s around 38 of them. Just 38! Even perlfunc documents more, somewhat around 270 functions, and I consider Perl to be a little on the cheap side.

Here’s how a real language’s quick reference should look like. A staggering 4942 functions, not counting class functions, and if you do, you’ll end up with 5312 functions. I don’t even want to know which are built-in, and which are extensions; with 5K functions, I couldn’t care less.

3. Ruby Has No Sense of Humor

Watch:

`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`

Now watch:

print map chr$_[0]-ord$_,@_='200ocT¨gZYT`cV¨xcV\¨`ge]cV'=~m;(\d+|.);g;

Can Ruby do this?

2. Ruby Has No Class

“Class in an object, Object is a class.” Ruby people just love to philosophize.

A Class in Ruby is just an object that can spawn new Objects. Classes can have methods attached to them, but not give these methods to their spawned ones. Objects on the other hand are instances of Class, and have their own methods that Class gave to them.

Not only that, but objects are open and can be overridden. This means that a method can be turned into an object, which then can be used as a block passed to another object, glued to a class, split across more objects, called simultaneously from difference threads, on different servers, redefined, then redefined again, twisted into obedience, bond to a master, and then beaten to death.

I’m not expecting you to understand, I couldn’t either. And Just so you know, capitalization in the quote above does matter.

1. Ruby Makes You Think

With Ruby, you have more than enough rope to shoot yourself in the foot. Good luck trying figuring out Ruby’s dynamicism (or the couple of paragraphs above). Ruby’s flexibility makes it very easy to write code than only you (and God) can understand.

If you want to write proper Ruby, you better understand classes and objects, lambdas, design patterns, mixins, threading, messages, and tons of other funny words, otherwise you’ll end up where you started: writing CMS software in PHP.

R.I.P. Microsoft

Microsoft’s biggest weakness is that they still don’t realize how much they suck. They still think they can write software in house. Maybe they can, by the standards of the desktop world. But that world ended a few years ago.

Paul Graham declared Microsoft dead, and his article strangely makes sense to me. Microsoft ruled the desktop for the past ten years or so, and I believe it’s becoming a much more difficult task.

Desktop software still has plenty of room. Just think of all the audio/video editing applications, photo manipulation, time-critical reporting, etc. If Microsoft figures out how to produce software that cannot possible be replaced by a Web-equivalent, they’d be back in the game.

I couldn’t help but smile a little when I read Paul Grahama’s article. Had it not been for Microsoft over-protective monopoly, we probably wouldn’t have had Linux “fighting back”, wouldn’t have witnessed Apple’s bounce-back, and wouldn’t have led FOSS into flourishing. We all needed a bully, and Microsoft was it.

Microsoft’s Dead. Long live Microsoft.

Fridge-top Website

Oh dear God I’ve away for a long time. This server was defaced a while ago, and I’m sorry that I’m back to WP’s default theme; but I’ll make it up. For now, let me just test the waters by dropping you a link to one of the most creative websites I’ve seen.

Via 37signals.

Tweets from