Sunday, December 03, 2006

Ruby Fan

Alright, I'm about 2-3 days into this Programming Languages Final Project - which (have I mentioned?) I'm doing in Ruby, and I would just like to say I'm damn impressed! As I've said before, I've messed around with Ruby some, but never really gotten my hands dirty. The point of this post is -> I'm not really getting my hands dirty now, either. Ruby is such a nice fit for Scheme that the code is practically writing itself!

Which is nice, because it lets me attend to the project during breaks from my final in Algorithms (which I really, really don't want to do, but it's down to the wire, so I'm running on 3.5hours sleep today). I should be able to finish it slowly over next week.

Do I anticipate rough spots? You bet! There are a lot of things in Ruby that don't work exactly as you'd necessarily expect, so I'm looking forward to spending most of next weekend tracking down (very) obscure bugs. But that can be fun too.

Anyway, I thought I'd take some time out to sing Ruby's praises. But then I thought, I don't have any time left in my bank account, so I'll postpone it for now and let this guy (via Lambda the Ultimate) do my talking for me. I agree with most of what he says here, and I'm not in the mood (nor have I enough free time) to get into the nitty gritty of what I don't - but it seemed to have some cool other links, so consider this a way of bookmarking it.

For my money, the main issue with Ruby was whether it was going to lend itself well to functional programming - and so far it's been very, very nice.

I do, however, have one GIANT complaint...

The argument to a lambda expression is referenced to local variables of the same name - which, aside from being highly annoying, is just deeply, terribly, awfully WEIRD and PERVERSE.

So if you do this (and why wouldn't you?):

x = 3
lambda{ |x| puts "Inside the function!" }.call(4)
puts x

it will print:

Inside the function!

I have no idea - I can't even imagine having an idea - why Matz would have done this. Clearly, x should be 3. (Everyone can see that.) But maybe there's an explanation out there somewhere. Anyway - this is what I mean by expected (very) obscure errors this weekend. lambda statements are supposed to create closures, so there's no reason anything inside the lambda statement should be able to see anything outside, necessarily. Actually, more specifically, it should NOT be able to see anything of the same name outside those curly braces. That is the whole bleeding point of a lambda. (Well, one of the bleeding points - the other is to have anonymous functions, pass them aruond, higher-order programming, etc. etc. Alright, so it's one of many bleeding points. A plethora of bleeding points, if you will. But that doesn't make it unimportant, damnit!)

So I'll have to watch out for stuff like that. More reports later. Right now I have to get back to the ever-so-interesting task of (well, first grading some papers, and then) figuring out where the cutoff point is between how large an integer needs to be before you tell the computer to throw caution to the wind and use the Karatsuba Algorithm rather than the one they taught you in 3rd grade (you know, multiply, carry, add, shift, next column, etc.). Fun, fun.


Post a Comment

Links to this post:

Create a Link

<< Home