Ruby is SO COOL!
by Pace on November 3rd, 2007 @ 9:37 am in
Off-Topic
Tags: LISP, Perl, programming, ruby
So, I decided to go with Ruby on Rails for this project, because I got so many opinions from either (or both) sides of the fence that it seemed like I couldn’t go wrong with either RoR or Django, and the tiebreaker is that Ruby is more Lisp-like, and Lisp is my favourite language. Boy, was this a good decision.
Ruby is SO COOL. It’s like a wacky chimera of Lisp and Perl, magically brought to life by a wizard waving a magic OO wand.
Ruby has many of the things I love about Lisp, like lambdas and closures:
def n_times(obj)
return lambda {|n| obj * n}
end
times23 = n_times(23)
times23.call(3) -> 69
Ruby doesn’t have macros (that I’ve learned about yet), but it does have code blocks, which are really frickin’ cool. They’re kind of like Java anonymous inner classes but far more flexible. Get this, as a toy example of a Lisp with-file macro:
class File
def File.with_file(*args)
f = File.open(*args)
yield f
f.close()
end
end
File.with_file("testfile", "r") do |file|
while line = file.gets
puts line
end
end
The do..end block forms a code block that is sort of passed to the with_file method as sort of an additional argument. It’s actually more like a coroutine to which control is surrendered by the yield statement. And the parameter passing can go both ways — yield can pass parameters back to the code block, as in this case it passes back the file handle, named f in the method and with a formal parameter name of file in the code block. If with_file were a Lisp macro, yield would be the comma.
And not only is the language itself really cool, but I really like the Ruby community. The foreword to the book I’m reading made me tear up:
“I believe that the purpose of life is, at least in part, to be happy. Based on this belief, Ruby is designed to make programming not only easy but also fun. It allows you to concentrate on the creative side of programming, with less stress. If you don’t believe me, read this book and try Ruby. I’m sure you’ll find out for yourself.”
-Yukihiro “Matz” Matsumoto, creator of Ruby
This post and its code examples were inspired by the PickAxe book.
- Related posts:
- Has my website been hacked into sending spam?
3 Comments!
#2 Posted by
nasir on November 6th, 2007 5:55 am | link
I totally agree what you said and I would like to add here Ruby is cool, Rails is cooler. It makes application development so easy.
I launched the first version of http://www.sphred.com in just 2 days and couldnt have imagine doing it with some other language or framework.
On top of that Ruby on Rails also makes adding new features so easy. I keep adding new features every couple of days by just working for an hour or two after my regular day job.
All the best with your new app.
#3 Posted by 2008 | Pace and Kyeli on November 2nd, 2008 6:15 pm | link
[...] November, Pace had fun with Ruby and Rails while working half-time as C9’s CTO. (She had not so much fun being a sysadmin, though.) Pace planned an elaborate anniversary surprise [...]













#1 Posted by
Megan M. on November 3rd, 2007 11:47 am | link
Holy cow, this is so exciting! And I barely understood a fraction of what you just said! And I’m still excited!!