James Britt wrote:
Chris wrote:
... in my estimation, the paradigm in Ruby is entirely different than in just about any other procedural language and even from the OO aspects of Perl, C++ and Java. To me, the difference between Ruby and just about anything else (common) is the same as when, in the development world, many of us made the leap from procedural to OO. I think the gap between Ruby and most everything else is that big -- as well as the payoffs...?
Could I can encourage you to go into more detail about this? In what ways do you see the Ruby paradigm as being s different from Perl, Java, and C++?
When you started learning Ruby, did you try to adapt familiar Perl/Java concepts/structures/object models to Ruby? If so, did this help or hinder your learning Ruby?
I think this is precisely the point and your question brings this out into the clear a little more. It would be a mistake IMO to try and approach Ruby with "Perl eyes." Sure, there are similiar things in both languages. It's hard not to think that Matz didn't borrow from Perl, ad in fact, I think he states this outright (as well as having borrowed from others as well.) Overall, I think it's a mistake to approach ANY language from the viewpoint of another to the extent it's possible NOT to do so. (If that makes sense?) This is the driving force behind my original question, so your question clarifies this more.
It's easier to make my point in Perl than it is in Ruby, but I'll try a couple of examples either way:
(1) The complete OO nature of Ruby IMO changes everything. Perl is still procedural in it's basic constructs. To iterate from 1 to 10 in Perl can be shortened *somewhat* from say C or Java using this construct:
for (0..9) { do_somthing_with( $_ ) }
But whether the above shorthand is used in Perl, or the traditional "C" way (eg. "for (my $i=0; $i<10; $i++) { do_something_with( $i ) }") it's still procedural. I think the Ruby way is significantly different:
10.times { |i| do_something_with( i ) }
To me, this is a significant difference and I think this gets magnified the deeper one goes into Ruby.
(2) I think the need to be familiar with the class methods and properties is magnified in Ruby. This is similiar to C++ where it's difficult to be productive unless one gains experience in the classes and methods available. In Perl, this is not as much the case, again do to the fact you can go completely procedural in Perl and get away with it. If you do use OO and modules in Perl, then you only need to know the methods for the module you imported and the rest can be procedural in Perl. In Ruby, it seems you can't really get away with that it seems.
(3) Another contrived example, this time in Ruby:
def Contrived
3.times { yield }
end
[ "tic", "tac", "toe" ].each do |item|
Contrived { printf "%s ", item }
printf "\n"
end
There is a lot about this that is different than Perl IMO. I could create an anonymous subroutine in Perl to function something like the yield block, and I realize the Ruby above is itself somewhat contrived, but... still, you wouldn't normally do something like this in Perl whereas in Ruby, these sorts of things are actually useful.
(4) Each language has it's own strengths. IMO one of Perl's strengths is the simplicity and consistency of it's parameter passing:
sub shell {
my @output;
for (@_) { push @output, `$_` }
chomp( @output );
return wantarray ? @output : \@output;
}
## My favorite "Rubyism" I use all the time in Perl -- puts()!
sub puts { for (@_) { print "$_\n" } }
puts( shell(
"ls -l",
"ps -ef | grep -i foo",
"rm *.bar",
));
You can't do something like that in many languages. Because of the parameter passing, procedures flow very well and usefully in Perl from one to the other. The same is true in every aspect of Perl and is in a very large sense how OO works in Perl. This is a Perl example of what I feel is probably lurking in Ruby. This is how I would do something like this in Perl that is not available really in this way anywhere else. My feeling is that the same sort of thing prevades Ruby. It "does things" that other languages can't do, including Perl.
So the point is I don't want to approach Ruby as Perl even though there are similiarities. Unfortunately, I see most people approach Perl in the same way as C and Java and JavaScript and Perl really looses it's benefits quickly when approached in this way. I don't want to do the same with Ruby.
Perhaps these weak examples answer your question. And so the original question, clarified more (more muddied more as the case may be), remains... Howz it feel to convert to Ruby _really_ and not just applying the "Perl" mindset to Ruby, which I think is a mistake. It's clear from even the basic constructs it isn't the same.
-ceo