True Properties Poll

Jesse Phillips jessekphillips+d at gmail.com
Fri Jul 31 13:27:18 PDT 2009


Nick Sabalausky Wrote:

> "Jesse Phillips" <jessekphillips+d at gmail.com> wrote in message 
> news:h4vg5q$13mn$1 at digitalmars.com...
> >
> > I find writing
> >
> > property int foo { get; set;}
> >
> > More work than
> >
> > public int foo;
> 
> That's an unfair apples-to-oranges comparison.
> 
> This:
> 
> property int foo { get; set;}
> 
> Is comparable to this current code:
> 
> private int _foo;
> int foo()
> {
>     return _foo;
> }
> int foo(int value)
> {
>     _foo = value;
>     return value;
> }
> 
> It is *not* comparable to:
> 
> public int foo;

I thought this might come up, but what do you gain from all that extra code? I heard mention of not being able to get the address of the field... but that is a very deliberate thing to do and should not be the purpose of getters/setters.



More information about the Digitalmars-d mailing list