Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17223 > unrolled thread
| Started by | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| First post | 2011-12-14 17:37 +0100 |
| Last post | 2011-12-14 17:37 +0100 |
| 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.
Re: Property Abuse Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 17:37 +0100
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
|---|---|
| Date | 2011-12-14 17:37 +0100 |
| Subject | Re: Property Abuse |
| Message-ID | <mailman.3648.1323880638.27778.python-list@python.org> |
Ian Kelly wrote: > 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 > I second this opinion, plain attributes are what's required most of the time. JM
Back to top | Article view | comp.lang.python
csiph-web