Nov 27
I've been putting it off for a few years now, but I recently found myself the proud owner of the Pickaxe book. (Thanks Ryan!) What once seemed as mindbending as hardcore Perl is now very much less so, and a pleasure to work with so far. Though only a week into learning Ruby, I'm happy to have made the leap.
Comments
Re: Pure object language
In Ruby, everything is an object. That includes primitives like int and boolean, which allows for some very cool new ways of thinking. So in your example, 10 isn't a literal; it's an object representing the integer value 10.
Constrast this with a C/Java/PHP style for loop:
for (int i = 0; i < 10; i++) { ... }
One has to do a bit of reasoning (however simple it may be) to figure out how many times the loop should run. Is it 9, 10 or 11 times? Ah... 10.
But, the Ruby loop is dead simple to read and it takes nearly a third less characters to type. :)
Re: Pure object language
"Things should be as simple as possible, but not any simpler." -A.E.
I very much agree that Ruby produces very readable code, but the overhead just seems a bit much. In truth, considering how rarely this type of construct will actually be used, it may just be a convenience thing. When was the last time you looped something over an exact value and not the size of another data structure?
my $i= scalar( @arr );
while( $i-- ){
# do something
}
Perl has it's own flavor of this, but instead of making literal values into objects it requires a special operator (like everything in perl):
while( 1..10 ){
print $_;
}
While Java can't compete with the Perl/Ruby whippupatude, it does offer a very readable method.
// yea, that's too much work to post
It seems like Ruby has taken object oriented just a little too far by making everything into an object. Maybe it's to promote good coding practices and creating readable code, but it still just feels wrong.
Pure object language
There are some strange language constructs. Consider this simple loop:
10.times { // do something }When did literals become objects? Joy.