Declarative properties
Diez B. Roggisch
deets at nospam.web.de
Sat Oct 13 14:15:29 EDT 2007
Dan Stromberg schrieb:
> On Thu, 11 Oct 2007 18:42:16 +0000, Marc 'BlackJack' Rintsch wrote:
>
>
>>> The "baggage" of possibly fixing (AKA "generalizing") how your attributes
>>> are accessed is something you lug around while your deadline looms.
>> Sorry I don't get it. If I want to customize the access to a "normal"
>> attribute I simply turn it into a property.
>
> You're right, properties are an intersting language feature. I wasn't
> aware of them until today.
>
> I'm not sure I believe they are better than disallowing public attributes
> and requiring setters and getters, but they do appear to address the same
> issue: the needless change in API when your internal representation
> needs to change.
This belief is most probably nurtured by Java. Or am I wrong here?
Matter of factly, the whole getter/setter-mamboo-jamboo is nothing but a
pathetic attempt to overcome the lack of attribute-access-hooks, as they
are e.g. provided by python or C#.
By forcing this convention upon the programmer (and supporting it using
e.g. BeanInfo and other introspection-based mechanisms), Java allows for
the implementation of delegation, lazyness and so forth without all that
forcing major interface changes upon the user. Talking of interfaces -
they do lack properties as well... so you _can't_ possibly provide an
interface with attributes.
But I really don't think one can argue over a more aesthetic &
expressive syntax like
a.foo = b.bar * c.baz
compared to
a.setFoo(b.getBar() * c.getBaz())
Diez
More information about the Python-list
mailing list