@property needed or not needed?
Rob T
rob at ucora.com
Mon Nov 19 01:11:44 PST 2012
On Monday, 19 November 2012 at 08:23:43 UTC, Jonathan M Davis
wrote:
> Which completely violates the concept of a property in the
> first place. It's
> intended to be an abstraction for a variable. Using @property
> just to get rid
> of parens would be like naming types with verbs instead of
> nouns. It's
> completely backwards.
>
> - Jonathan M Davis
I know what you are saying, but I know that most people will
usually follow the path of least resistance, so if a lot of
people really dislike typing in () all over the place and are
given a way out, then they'll likely take it, so long as it won't
matter in any significant way in terms of practicality.
Another case that I would say violates the property concept, is a
getter property function that returns a non-const ref, and
reusing the same property function as a setter (for cases where
there's nothing to be done when setting). It is less work when
you can get away with defining one property function that looks
like two, even though it may be bad in some way, I expect it will
be done often.
I suppose with @property enforcement in place, the compiler can
be adjusted to prevent non-const ref return values for property
getters. That would also make it a bit more difficult to specify
@property just to get rid of typing ().
The big question is what do we gain and what do we lose from
enforcements like this? It has to be worth doing, or it should
not be done,
Personally, I think we're much better off not attempting to
enforce coding style through restrictions that could be viewed as
unnecessary.
--rt
More information about the Digitalmars-d
mailing list