ruby? i'll sell it
Say you've got to process a file, you'd do it like this in perl (my python sucks, you don't wanna see it)
open(INFILE,"</path/to/file");
while (<INFILE>) {print $_;}
close INFILE;
or something similar.
In ruby
File("/path/to/file") {|x| puts x}
now understand that's a grossly simplified example. But note that it takes care of allocating and deallocating the filehandle for you.
Now let's try some string manipulation...
We have inline regexps, perl style, lovely, unlike ****ing with the python regexp objects.
x =~ /([a-z]+)/
print $1;
something like that. Saves a lot of time over the python version
Then there's all the lovely methods attached to objects
puts "blah".reverse
print ("2122".reverse.to_i - 100)
see that, i reversed it and then converted it to an integer, all in one statement. quick and easier to follow
The classes that come with ruby are more logical and easier to use, and they have a lot of nice functionality, and many shortcuts. An example is the Marshal class. Being a python god you'll know all about saving dictionaries to file, i presume. Well the marshal class saves any object in a marshalled form that you can get easy access to. Imagine sending it over the net and being able to take it apart again nicely :) Well it's a good example
require 'Marshal'
marshalledhash = Marshal(myhash)
now, we could have passed in a second parameter, filename, which would save us writing this to file, since that's one of the common things you want to do with marshalled objects. Every core class is like this, and other classes try to be like this. An example is ruby-gnome2, which is ridiculously easy to use. Cool, I swear.
Ruby also excels when it comes to hashes (dictionaries) and lists (arrays).
Try this for size
{x=>5,y=>8,z=>9}.each {|x,y| print "#{x} = #{y}"}
that #{} business was interpolation, btw, interpolating the variables into the string.
other methods on hashes include the standard python kit i suppose, keys, values, etc.
what python doesn't allow you to do is construct a simple loop like that with a passed in lamda (the block in brackets is a lambda function, called a block that is activated within the class in a special way). python's lambdas really suck ***, only allowed to be one statement and all... Try this for size
myarray.each do |x|
x.chop!
print x[4]
end
That was two statements, counting as a block too, and i could have done more. And you'll also notice i used array notation on a string. that gets the character at that position, like you'd use on a python list to get a member. you can also use the python syntax to get a subset of the results
x[1...3]
x[-3...-1]
etc.
there are just so many neat things built in, y'know...
creating your own functions that accept blocks is easy too
def myfunc (x,y)
yield #This is what calls the optional lambda block there.
end
if it suits you, you CAN also pass a lambda directly as an argument if that's what the function expects
myfunc(x, lambda {|x| puts x})
but seriously, me talking about it won't do a thing to convince you, you've gotta try it to know.