Thursday, April 07, 2005

Ruby: Not quite as shiny as one would hope.

Right, what with all the hysteria surrounding Ruby on Rails , I decided to give Ruby and RoR a bit of a whirl.

I was quite disappointed with the almost vertical learning curve of Zope and quite open to abandoning Python and defecting to the dark side of the force. Matz rasping "I am your father..." after he's lopped off your hand can do that to you :-P

So any, after around a week of reading, I'm back in the Python camp and on my knees begging for forgiveness and integration back into the Hive.

What happened?

Ruby happened.

So what's this short foray into enemy territory taught me?

A. The positives.

Ruby has a lot going for it. Its OOP mechanism are much cleaner than Pythons and closures are cleaner and feel more expressive. In addition, the language supports threading, which is great. JRuby is under active development, unlike the recent history of Jython (although that's changed recently with the reactivation of that project with a fresh infusion of blood (and cash!)). The .. and ... are handle stuff sweetly in for loops too.

The community's great and the platform is still far from being fully formed, so your opinions can actually help direct the future of Ruby.

B. The negatives.

Ah, now we get to the meat of the matter. Wait, I'm going to need a numbered list for this :-D

  1. Magic variables: I left Perl and joined up with the Python camp because I hated stuff like $_, $1, $2, $foo etc. I know it's possible to avoid using these in Ruby, but not everyone's as fastidious as I am and reading this kind of code leaves a bad taste in my mouth.
  2. Crap variable names: $why $do @I have_to @@Name $my variables LIKE @this? $pare $ME!
  3. Verbose block delimiters: What exactly does one gain by using BEGIN..END versus {..} or significant indentation?
  4. Weak Libraries: One of the greatest strengths of Python, Perl, Java and other mature languages/platforms is the vast array of easily accessible libraries. It makes coding up a useful application quickly very easy. Ruby's lack of robust industrial strength packaged libraries is a major failing.

You'll notice that points 1..3 relate directly to syntax. I know the niggles seem a little petty, but things like this do matter when your coding. I want something I'm going to be interacting with for several hours everyday, to be smooth and pretty. It's something which is important to me and I'm sure to a lot of other people out there.

As for Rails... I admit that I haven't really gone all that deep into it, but that's because even a cursory examination revealed it to be heavily magical. Far too many things just 'happen' and although it may speed up initial coding, it will come back to bite you later. Besides all the squealing about 10x improvements in productivity remind me of Fred Brooks essay, No Silver
. Some one should send the RoR cheerleaders a link.

And I've discovered frameworks other than Zope for Python.

More on that later.




Anonymous said...

"# Crap variable names: $why $do @I have_to @@Name $my variables LIKE @this? $pare $ME!"

That's totally false. Ruby doesn't force you to name variables that way at all. (Rails doesn't either, btw.) Look at the online version of the chapter on objects and variables in the Pragmatic Programmer's Ruby guide for more.

Anonymous said...

"Magic variables.."

That's not quite true. These magic variables appear only in one, entirely optional context in Ruby: when you want to do "object-oriented" regular expressions. See this chapter in the PP's Ruby book for more details (scroll down to "Object Oriented Regular Expressions".)

However, most Rubyists simply use the more common standard regex notation like "b = /^\s*[a-z]/". Use those and you'll never need the $ notation.

Arsalan Zaidi said...

Example variable and class names
Variables Constants and
Local Global Instance Class Class Names
name $debug @name @@total PI
fishAndChips $CUSTOMER @point_1 @@symtab FeetPerMile
x_axis $_ @X @@N String
thx1138 $plan9 @_ @@x_pos MyClass
_26 $Global @plan9 @@SINGLE Jazz_Song

There you go, that's from
The formatting's all messed up, you'll have to go to the link to see it properly.

Also, about the regex related magic variables. Notice that I said you can use them. I know I won't, but others will; and I'll end up having to read that crap code!

dulce445bryana said...

damn good blog, check out mine, comments always welcome!

PHP Guy said...

cool documentated!

nikhil said...

One really cool Ruby thing you left out was the way one iterates over collections and hashes.

I mean where can you do the following:

shows.sort! {|a,b| a.show_date <=> b.show_date}.each {

I've been a J2EE developer myself for the past 6-7 years and believed that nothing could be more productive than Spring/Hibernate/Struts combo for web development.
Well after developing in Ruby for the last 2 months, I now realize how wrong I was.