From: Brian Wisti Date: 2004-09-16T03:51:13+09:00 Subject: Re: Ex-Perl coders: Howz it feel to convert to Ruby? Hmm ... TMTOWTDI applies in both Perl and Ruby. I think I would have written most of your examples differently, and that difference is probably why Perl<->Ruby isn't a big deal for me. > (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( $_ ) } foreach my $i (0..9) { do_something_with($i) } or even map { do_something_with($_) } (0..9); > 10.times { |i| do_something_with( i ) } 0.upto(9) { |i| do_something_with(i) } > To me, this is a significant difference and I think this gets > magnified > the deeper one goes into Ruby. True enough, but presumably your understanding deepends as you go deeper into Ruby, yes? > > (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. Sure, but POLS is a decent guideline, and when all else fails I call obj.methods() from irb to see what I get to play with. I generally don't need to refer to docs for libraries that I haven't imported, so I'm not sure I understand that bit. And maybe things aren't as straightforward in Perl as you describe. One still has to be familiar with the full standard library, the various sigils, the built-in types, and all of the modules that you've imported. > > (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. Useful, sure. Widely used, you betcha. Fact is that I've still never needed to use yield in any production code. Use what you need, not what you feel like you're supposed to. Your sample Perl code didn't show taint-checking or full conformance to strict and warnings, even though that is widely promoted as the "right way" to do things. > > (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", > )); Yup, it's a strength of Perl, and that's a nifty puts subroutine :-) > 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. What's wrong with taking advantage of the languages that Ruby builds on? Familiarity with Perl, Python, Smalltalk, and LISP are all incredibly useful with Ruby, and sometimes a design is easiest to express in something resembling one of those languages. I can see a problem with trying to make your Ruby code look *exactly* like Perl code, same as writing a C-style for(;;) loop instead of a for/foreach loop in Perl is ugly. But hey, sometimes it's useful. I don't knock what works, as long as I can read it :-) > > 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. Sure, it's not the same. But insisting on doing things the "Ruby Way" immediately is naturally going to result in a serious dip in productivity compared to going out and writing code that works, right away. But this is a philosophical difference, and I doubt that our philosophical worlds will intersect much ;-) Kind Regards, Brian Wisti http://coolnamehere.com/