Nick Sabalausky wrote:
"Leandro Lucarella" <[email protected]> wrote in message news:[email protected]...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"):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.
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:[email protected]
http://jeberger.free.fr
Jabber: [email protected]
signature.asc
Description: OpenPGP digital signature
