NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Pimping Ruby (Score:2)
I 've been trying to maintain some legacy code that badly needs updating. One of the main sins committed in this code is direct object access, so $obj->{attribute} = 'value', rather than $obj->set_attribute('value');
This is one of those areas where Ruby's Uniform Access Principle demonstrates just how clunky Perl's OO and accessors really are. To wit:
"But, wait!", you cry. "Accessing the attribute like that is an encapsulation violation!"
You're not accessing the attribute directly. The syntax just makes it *look* like you are. In reality you're calling the Foo#attribute= method. This longhand example should clarify things:
Re: (Score:1)
This is one of those areas where Perl 6's Uniform Access Principle demonstrates just how clunky and non-uniform Ruby's instance attributes are.
Re: (Score:2)
Personally, I think it's a misfeature, because I don't always want users to have access to the instance variables I'm using. I'm sure that's configurable, too, but I'd rather be explicit than implicit in this case. Or, just write a custom 'is' method that lets me imitate the Perl 6 syntax.
The topic of autogenerating a
Re: (Score:1)
I actually meant that most of the Ruby code I've seen accesses instance variables directly within the class, despite the presence of an autogenerated accessor. There's a subclassing problem there. (Actually it's not only a problem for subclassing, but I use that as a convenient shorthand because I don't have a good way to say "allomorphic instance modification".)
I've never seen a clamoring for
Re:Pimping Ruby (Score:2)
Reply to This
Parent
Re: (Score:1)
It's only a problem if a subclass wants to do something different with an attribute. I run into that once in a while.
Re: (Score:2)