From: Paul Brannan Date: 2001-10-30T22:44:54+09:00 Subject: [ruby-talk:23841] Re: RCR: Fun with attribute shortcuts solves RCR #3 and more On Tue, 30 Oct 2001, Avi Bryant wrote: > On Tue, 30 Oct 2001, Albert Wagner wrote: > > > Wow, keep this up and you can boil a whole application down into a single > > obtuse statement :-) > > Actually, I find such methods much less obtuse than the code they replace. > Although it's very easy to recognize an accessor method when you see one, > using attr_accessor makes the concept more explicit and more readable, > not less. Similarly, == methods impose a certain cognitive load when > reading them; I have to read the entire method to make sure it doesn't do > anything unusual. With attr_equality, I know that the implementation of > the method is the usual one. Macros and metaprogamming are not about > obfuscation - quite the opposite, in fact. The more you can bring > explicit design concepts and vocabulary into your code, the better. What is attr_equality? I've never heard of this. I wonder how this would be implemented for the general case (and what the general case is)? One interesting idea this brings to mind is the idea of a "const method". A const member function in C++ cannot modify non-mutable members. One interesting possibility in Ruby would be to 1) temporarily freeze the object, 2) call the method, and 3) unfreeze the object if it was not originally frozen. Instance variables could even be marked as mutable, if so desired, and could always be modified, even when the object is frozen (this functionality is already available to C extensions, if the author forgets to check to see if the object is frozen before modifying it). Paul