DIP4: Properties
Leandro Lucarella
llucax at gmail.com
Fri Jul 24 14:28:01 PDT 2009
Nick Sabalausky, el 24 de julio a las 16:16 me escribiste:
> "Chad J" <chadjoan at __spam.is.bad__gmail.com> wrote in message
> news:h4cv6h$st6$1 at digitalmars.com...
> >
> > Have you checked out haXe's syntax for properties?
> > http://haxe.org/ref/properties
> >
>
> Yes, in fact, I've been using haxe a lot lately for work. It certainly beats
> AS2 and PHP, but there's still a lot about it I really dislike, and it's
> property syntax is one of my biggest complaints.
>
> For those not familiar with haxe, compare the following property in my
> current D proposal, the equivilent C#, and the equivilent haxe:
>
> --------------------------------
> // D, current DIP4
> public int foo
> {
> get { return value; }
> set { value = set; }
> }
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. And I think there should be a way to get
the real underlaying variable easily.
What about:
public int foo: _foo
{
get { return _foo; }
set(v) { _foo = v; }
}
Then, when you want to use the real internal variable, you just use _foo.
Even when you are repeating yourself, the internal implementation and the
external interface are decoupled; you can rename the property to bar
without changing the implementation:
public int bar: _foo
{
get { return _foo; }
set(v) { _foo = v; }
}
The default protection attribute for underlaying property variables are
private, but you can change it with:
public int bar: protected _foo
{
get { return _foo; }
set(v) { _foo = v; }
}
I think is is not much harder to write and maintain comparing with what
you proposed, but I find it a lot more explicit and thus clear. You don't
have to remember where that automagically variables came from. You can
implement properties without even a real storage variable using your form:
public int baz // readonly
{
get { return 1; }
}
What do you think?
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
PROTESTA EN PLAZA DE MAYO: MUSICO SE COSIO LA BOCA
-- Crónica TV
More information about the Digitalmars-d
mailing list