DIP4: Properties

"Jérôme M. Berger" jeberger at free.fr
Sat Jul 25 02:44:37 PDT 2009


Nick Sabalausky wrote:
> "Leandro Lucarella" <llucax at gmail.com> wrote in message 
> news:20090724212800.GA2120 at homero.springfield.home...
>> I think you have good points about not repeating yourself, but I still
>> find it too magical. I think I prefer something a little more explicit,
>> even if I have to repeat myself.
> 
> I assume you're referring to the automatic "value" and "set" variables here, 
> right? The proposal seems to be getting a lot of complaints about those. 
> But, I haven't seen any explanations of actual problems with them beyond 
> "it's magical", "I prefer", etc (unless I've overlooked something, and my 
> apologies if I have). Any abstraction could be argued to be "magical".
> 
> I'm getting the impression that this may be a case of an idea meeting 
> resistance more from being different than from lack of merit. Of course, it 
> could also be that I'm just being overprotective of a bad idea. Can you or 
> someone else provide a more detailed argument/example/explanation for a 
> problem with these automatic vars?
> 
> As I do seem to be the only one in favor of these automatic vars though, I 
> am willing to omit them from the proposal in the interest of (hopefully) 
> getting at least *something* better than the current state. But, I would 
> hate to have to do so without having been presented a deeper argument 
> against them.
> 
	What about properties with no underlying storage? For example a 
Complex class needs four properties: "real", "imaginary", "module" 
and "argument", but it only needs storage for two of them (usually 
"real" and "imaginary"):

class Complex {
private:
    double _real;
    double _imag;

public:
    double real {
       get { return _real; }
       set { _real = value; }
    }
    double imag {
       get { return _imag; }
       set { _imag = value; }
    }
    double module {
       get { return sqrt (_real*_real + _imag*_imag); }
       set {
          /* Some code to set both _real and _imag so that the
           * module will take the new value and the argument
           * won't change */
       }
    }
    double argument {
       get { return atan2 (_imag, _real); }
       set {
          /* Some code to set both _real and _imag so that the
           * argument will take the new value and the module
           * won't change */
       }
    }
}

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090725/9356cc04/attachment.pgp>


More information about the Digitalmars-d mailing list