From: Mathieu Bouchard Date: 2001-12-08T13:29:52+09:00 Subject: [ruby-talk:27895] Re: Perl/Python Module Porting On Sat, 8 Dec 2001, Eric Lee Green wrote: > Only problem with most Perl modules is that they are FAR from being > object-oriented. Thus you can't just take a Perl API and port it to Ruby > (with the exception of the very few Perl modules that are object-oriented). I'd instead say that it's because there are a number of Perl features that are not found in Ruby: 1. tie(). This takes a builtin type and turns it into an abstract class for which you provide an implementation. Ruby has its builtin types as ordinary classes, but there's still a mismatch. MetaRuby (see RAA) takes care of ARRAY and HASH; but nothing takes care of IO and SCALAR yet. IO can be fixed, but... 2. In Ruby, there is _no_ equivalent to SCALAR. In Ruby, variables are not objects; in Perl they are fcv ("first-class value") 3. In Ruby, there is _no_ equivalent to GLOB. Well, neither in Perl4 nor Perl6, but most of Perl code nowadays is Perl5. Many uses of GLOB can map to Ruby's "alias", but many can't. 4. In Ruby, values are passed to functions; In Perl, variables are passed instead, though most code revert to value semantics by copying the parameters to local vars. 5. Perl has contexts; most prominently, returning a "list" is not the same as returning a "scalar array ref", and returning a "scalar value" is not the same as returning a single-element list either. 6. In Perl you can modify inheritance on the fly. This may mean deleting superclasses. 7. Perl's SUPER restarts lookup (Multiple Inh); Ruby's "super" resumes lookup (Mixin Inh). 8. Perl makes a difference between objects and non-objects; objects are implemented on top of non-objects: hashes, arrays, scalars, ios, subs, globs; most of those can be in turn "tied" (see #1), which means that instance variables themselves may trigger method calls. (I've seen this used as a basis for a persistence model.) > Python modules tend to be a little easier to port. I'm thinking about > porting some of mine to Ruby, but lack of time (sigh).... That's because Python/Ruby are more similar than Python/Perl and Ruby/Perl, (even) when not considering the syntax. The OOness is only a part of this. ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju