PEP 8 and properties

Jonathan P. jbperez808 at yahoo.com
Mon Jan 20 19:45:43 EST 2003


"John Roth" <johnroth at ameritech.net> wrote in message news:<v2mlb2s499teb2 at news.supernews.com>...
> I think there's some confusion here. The dictum that
> you don't expose variables comes from the "information
> hiding" school of thought. A variable is part of the
> internal implementation of the class, and you should
> be able to change it freely. A function, on the other
> hand, is part of an API, and doesn't constrain changes
> to the implementation nearly as much.
> 
> Now, if the language includes properties, then the
> assessment changes, because there is no external
> difference between variables and properties. You
> can publish a variable, and then if you want to change
> the implementation so that the variable doesn't (even
> conceptually) exist any more, you can make it
> a property, which lets you slide the accessor functions
> in under the hood.

In other words, properties let us have our cake and eat
it too.  But they are flexible enough that you're going
to have to enforce some strict conventions on their usage
to avoid possible confusion.  I'm starting to see how
they can be Pythonic.




More information about the Python-list mailing list