Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17221
| References | <CAAfDykva2jyARQpAxrLK2V4UD_G56ZTxX0b+HSHHsdQyPma_YA@mail.gmail.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2011-12-14 09:27 -0700 |
| Subject | Re: Property Abuse |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3647.1323880094.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Property Abuse Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-14 09:27 -0700
csiph-web