PEP 8: on member variables vs. attributes

John Roth johnroth at ameritech.net
Sat Jan 18 23:32:22 CET 2003


"Jonathan P." <jbperez808 at yahoo.com> wrote in message
news:f57664b9.0301171939.387f4351 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)...
>
> I get both your points.  I guess my precise question would
> be:  Doesn't the recommendation to use properties (for
> its syntactic sugar benefits) essentially deprecate the
> suggestion to make a 'functional' interface to your class?
> Properties, after all, are identical in usage to attributes.
> I guess better clarifying language is needed in the PEP.

If it looks like a variable, use a property. If it does something,
use a method.

Variables don't cause any action when they are retrieved
or set. They may very well change other actions later, but
they don't have any immediate behavior.

Functions do. That's the basic difference, and it's that
guarantee that makes your code clear.

John Roth






More information about the Python-list mailing list