So I've been playing with Ruby for whole two days!
I had to update our backup script for subversion repositories (was written in shell) so I decided that it would be nice to learn something by the way.
I can't publish the script (sorry, corporate policy :-( but I can write about my feelings about ruby.
Let's start that it was easy to find tutorials and documentation. That a must have for any new language that wants to be popular. I've been satisfied with ruby documentation available on-line. I haven't checked ri manuals yet. I used only simple stuff from core library.
Ruby's nice, easy to start with. I recently started using python. So I can compare how easy was to start with any of them. I must say I think it was easier with ruby. But I have some concerns about this language - read on.
First I must say I'm impressed with ruby's closures - a closure is an anonymous block of code that can be executed or passed into a function, etc. So you can for example call a method with some code that you want it to execute, you don't have to specify interfaces, implementation like in Java. You just write you code. Easy as that!
Closures are great for controlling resources and preventing resource leak. Let me explain. If you want to read something from file you can do something like that:
File.open("path", "r") do |file|
integerValue = file.read.chomp.to_i
end
What it does? It will open a file, run your code, close the file. In case there's a problem reading the file resource will be closed and you don't have to worry about it. Between "do" and "end" there's an anonymous block of code that will be given to open as an argument.
What else I like? Exception handling is interesting. First it doesn't follow of common naming convention as: try/catch/finally. You can begin (try), rescue (catch), ensure (finally) and
else! "Else" is used when you want to do something only when there was no exception. Nice, isn't?
Other interesting things - you have block of code with beginning and end so it's not like in python - you don't have to keep your indentation.
Function is not a function - it's a message (like in SmallTalk). Objects respond to messages. It's easy to create a proxy that sends different messages to different objects, you can add some tracing on your objects easily, you can decide in code which messages are active on the runtime!
The world of mix-ins - sometimes there's some functionality that can be shared between many objects. Ruby allows you to keep it in some separate module and include it to your objects. Yup, you don't have to extend a class, you can just share some code.
Strange things - you can define a new function (message endpoint) on an object - an instance not a class. In this case all other objects of the same type will not have it!
Type safety is strange. It's nothing you're used to. Ruby implements tactic if something ducks treat it like a duck. That's possible because every function is a message so you can just send any message to any object.
You can do something like that:
duck = MyDuck.new
dog = DockThatDucks.new
animalsThatDuck = [ duck, dog ]
animalsThatDuck.each do |animal|
animal.duck
end
Dog that ducks is a duck, isn't it? ;-)
I enjoyed using ruby but I'm full of concerns. Sure it's nice to code but I'm not sure that you can build something big on it. I feel that it's too close to become next PERL in which it's easy to write something, it's impossible to read code ;-)
Closures are a tempting tool but they can be overused. Also mix-ins. It can be a PITA to find what's extending what and why or when.
Wojciech some time ago wrote about project done by ThoughtWorks in JRuby on Rails. I wonder how their code looked like. That code could prove that either Ruby's is or not good for large projects. Sure it's cool (as any other new, shiny thing ;-) but will it survive next years?
I'd like to get more familiar with Ruby on rails then I'll can tell more.