Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17223
| Date | 2011-12-14 17:37 +0100 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: Property Abuse |
| References | <CAAfDykva2jyARQpAxrLK2V4UD_G56ZTxX0b+HSHHsdQyPma_YA@mail.gmail.com> <CALwzidn3EO1en5Rq9GfD7rNqgogJziy6kMAMa7kFow0Gezj53Q@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3648.1323880638.27778.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Property Abuse Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 17:37 +0100
csiph-web