Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17221 > unrolled thread

Re: Property Abuse

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2011-12-14 09:27 -0700
Last post2011-12-14 09:27 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Property Abuse Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-14 09:27 -0700

#17221 — Re: Property Abuse

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-12-14 09:27 -0700
SubjectRe: Property Abuse
Message-ID<mailman.3647.1323880094.27778.python-list@python.org>
On Wed, Dec 14, 2011 at 1:28 AM, Felipe O <pip.261@gmail.com> wrote:
> Hi All,
> I was wondering what everyone's thought process was regarding properties.
> Lately I find I've been binging on them and have classes with > 10
> properties. While pylint doesn't complain (yet), it tends to be picky about
> keeping instance attribute counts low, so I figure there's something against
> that. How do you guys decide between using properties versus getter methods,
> or how do you refactor them if neither?

I prefer direct instance attribute access where possible*, properties
where necessary, and methods where an argument is needed or the
relationship is more complex than get/set/delete.

* One of the strengths of Python's property system** is that you can
switch between plain attributes and mutable properties as needed
without breaking dependent code.  Often I see people doing this, which
drives me nuts with its useless verbosity, when a plain instance
attribute would have sufficed:

    @property
    def foo(self):
        return self._foo

    @foo.setter
    def foo(self, value):
        self._foo = value

** As opposed, for instance, to the .NET property system.  You can't
arbitrarily switch between public member variables and public
properties in .NET, because it breaks ABI.

Cheers,
Ian

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web