The best kittens, technology, and video games blog in the world.

Friday, May 05, 2006

Baby pandas, or how to fight evil with cuteness

First, take a look at the baby pandas. Do we all agree that they're very cute ? Ok, so as we do, let's get to the point: Why do people still use C/C++ ? Now, sure sometimes you already have a chunk of code in C/C++ or need some extra performance or whatever. But I think most of the time people use it just because it takes too much effort to switch to something else, even if at conscious level they "know" the other language would be better for them. It's just that in the small thing they're doing right now it's faster and easier to stick with the old methods. How do I know it ? Well, I've been using Perl for most of the scripting, even though I know that Ruby has all the nifty things that Perl does not. I've Perlscripted things so many times that I can write Perl one-liners (equivalent to 100 lines of Java) without even looking or being aware of what I'm typing. ^_^ With Ruby I still have to think what I'm typing. But that won't last any more - from today I'm not going to code anything in Perl if it can be done in Ruby (that is - unless I'm modifying some Perl program like tawbot). The first effect of it is the following code:

ruby -le 'STDIN.map{|line|line} .scan(%r[http://www.\S+.com\?epDate=\d+-\d+-\d+])} .flatten .uniq .each{|url| system %Q[wget "#{url}"]}' <index.html
It mirrors whole archive of a certain webcomics. Now it Perl it would be:
perl -nle 'print $& for(m[http://www.\S+.com\?epDate=\d+-\d+-\d+])' <index.html | sort | uniq | perl -nle 'system qq[wget "$_"]'
It's a bit nicer in Ruby, not having to use external programs sort and uniq and without some of the Perl's line noise. So back to the baby pandas - Ruby is cute, baby pandas are cute, if you're still using C++ instead of some cute language you're hurting baby Pandas. You don't want to hurt baby Pandas, do you ?

5 comments:

Anonymous said...

Ah, tell me more. I keep promising myself that I will learn Ruby, yet I still keep using Perl for everything (inluding using Perl as a stub for not having a proper Unix-shell on Windows ^_^)

taw said...

For one-liners like that Perl is about as good as Ruby. So you won't see any huge benefits straight off. The thing is - most of the small-to-medium sized programs to automate various tasks start as one-liners.

So when I write a one-liner in Perl, I usually write the whole program in Perl and that's somewhat less cool than using Ruby (advantage of switching from Perl to Ruby is of course much smaller than from Java/C++ to Perl, but it exists nonetheless).

And if you want to know more about Ruby, just watch the movies, because Seeing is Believing.

Anonymous said...

Like, perl, like, will be there forever, and ruby, like, will be forgotten, and all your ruby scripts will be useless, like, soon.

And, like, who knows ruby? If you, like, publish your ruby script, fewer folks will benefit.

That said, I'll watch the presentations.

taw said...

I partially agree with you, that Perl will be there forever, and that fewer folks knowing Ruby than Perl is a pretty good argument for Perl.

But on some points I disagree. First, there is very little chance of Ruby (or Perl, or any other language) simply going away. Few languages have ever gone away, people still use Fortran, Cobol and the language used in Sendmail configuration files, and they're about twice as old as I am and almost everybody agrees that they produce a lot of vacuum.

So even if everybody decided tomorrow that Ruby totally sucks, it's very likely to continue its existance indefinitely. And Ruby is not an obscure or dying language, even if its not exactly top 5. ^_^

The second and I think more important thing, I think Perl is not going forward for quite some time now.

Perl is really a great language, and it introduced many cool features (like regular expressions as part of the language) to the mainstream, and some of its nifty features (like autovivification) aren't available anywhere else. And I think everybody agrees that it needs some cleanup, like a decent syntax for the most common OO constructs, universal print that gets rid of Data::Dumper etc.

However, in about 2002 some otherwise very smart guys got a really really really dumb idea of totally rewriting Perl. Four years later, they don't even have betas. I suppose that if they worked on the old code base instead, Perl 5.something would be there today and at least some of the cruft would be cleaned up.

So I predict that by 2010 we'll have a choice of really cool Ruby 2, stagnant Perl 5 and still-vapourware Perl 6. So I guess I'll take Ruby. Of course if Perl 6 actually gets released and lives up to even half of the buzz, I might switch languages again. ^_^

Anonymous said...

"And, like, who knows ruby? If you, like, publish your ruby script, fewer folks will benefit."

Like what?
Both ruby and perl have a big community. And ruby has a lot more momentum in the recent years than perl, plus ruby does not carry the adage of old diseases that perl has. Ruby's OOP is a lot more elegant than perl's vapourware ever will.