PEP 8 and properties
John Roth
johnroth at ameritech.net
Fri Jan 24 15:52:57 EST 2003
"Ian Bicking" <ianb at colorstudy.com> wrote in message
news:mailman.1043357026.17812.python-list at python.org...
> On Mon, 2003-01-20 at 20:41, John Roth wrote:
> > I think so. As far as I'm concerned, the difference
> > is that a variable is something, while a method does
> > something. I know this isn't as clear a distinction as
> > I'd like, but then, most things have real fuzzy edges.
>
> This was my initial thought too. Or I'd say, anything that has side
> effects should be a method. So I've been using properties for
> calculated or dependent values, so I might have a color object that
has
> red, green, and blue attributes. It also has hue, saturation, and
value
> attributes. Red, green and blue are orthogonal to each other (though
of
> course limited to be numbers, etc). But they are not orthogonal to
hue,
> saturation and value. Obviously one of these is calculated, though it
> could actually be either one. Or heck, hue, value and green could be
> the master attributes (if I wanted to work out the math :).
>
> But okay, I'm fine with that. I'm also okay with side effects that
are
> for caching purposes. If you have calculated values it's only normal
to
> add caching at some point in the process, and you don't want to change
> the interface in order to do that. I'm also okay with side effects
that
> might even involve writing a cached value to disk.
>
> But then there's other calculated values I'm not so sure about. In
this
> example maybe something like isBlack. It's kind of calculated, but
it's
> constant for the color (assuming the color is immutable). It would
> certainly never take an argument. But I'm a little less comfortable
> with this... somehow it seems wrong for a test to be an attribute, and
> not a function. But I know a lot of languages with properties use
this
> style often.
Intuitively, I'd agree with you. isBlack() certainly looks like a
function to me, not a variable. In fact, it intuitively suggests that
there
is an underlying variable named 'color.'
In general, "is" questions are, to me, functions.
John Roth
>
> I feel like there's other cases I haven't come up with, where the
rules
> I've decided on so far don't apply, or they do but I disagree with
them
> for that case. There's no Python convention to go on in these cases,
> either.
>
> --
> Ian Bicking Colorstudy Web Development
> ianb at colorstudy.com http://www.colorstudy.com
> PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
> 4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241
>
>
More information about the Python-list
mailing list