PEP 8: on member variables vs. attributes
John Roth
johnroth at ameritech.net
Fri Jan 17 07:47:12 EST 2003
"Jonathan P." <jbperez808 at yahoo.com> wrote in message
news:f57664b9.0301170041.46cc103e at posting.google.com...
> From PEP 8:
>
> Designing for inheritance
>
> ... In general, never make data
> variables public unless you're implementing essentially a
> record. It's almost always preferrable to give a functional
> interface to your class instead (and some Python 2.2
> developments will make this much nicer)...
>
> But don't properties and data variables (as attributes) look
> the same anyway? So what's the diff between them, functionally
> speaking? Hasn't it been decided that get/set accessor
> functions are a real hassle and that is why we see the concept
> of a property replacing that of accessor methods (Delphi's
> Object Pascal seems to have pioneered this) in newer
> languages like C# and now also in Python via descriptors?
> That would seem to contradict this particular point found in
> PEP 8.
They look the same, but they aren't the same thing at all.
Properties are simply a piece of syntactic sugar on top
of accessor functions. As such, they provide the same
information hiding benefits as accessors.
It's a nice piece of syntactic sugar, but it does not provide
anything fundamental that can't be accomplished in some
other way.
What it does provide is clarity and a level of encapsulation
that facilitates maintenance.
John Roth
More information about the Python-list
mailing list