Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'instance,': 0.05; 'attribute': 0.07; 'lately': 0.07; 'tends': 0.07; "everyone's": 0.09; 'mutable': 0.09; 'necessary,': 0.09; 'am,': 0.12; 'def': 0.13; 'argument': 0.15; '@property': 0.16; 'arbitrarily': 0.16; 'methods,': 0.16; 'opposed,': 0.16; 'versus': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'instance': 0.18; 'cc:no real name:2**0': 0.20; 'cheers,': 0.20; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'breaks': 0.23; 'complain': 0.23; 'cc:2**0': 0.24; "python's": 0.24; 'classes': 0.26; 'code.': 0.26; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'useless': 0.30; "i've": 0.31; 'dependent': 0.32; 'wondering': 0.32; 'received:209.85.161.46': 0.32; 'received:mail- fx0-f46.google.com': 0.32; "can't": 0.32; 'decide': 0.33; 'something': 0.35; 'switch': 0.35; 'received:209.85.161': 0.36; 'properties': 0.36; 'drives': 0.37; 'variables': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'doing': 0.38; 'using': 0.38; 'received:209.85': 0.38; 'plain': 0.39; 'received:209': 0.40; 'more': 0.61; '2011': 0.61; 'property': 0.63; 'direct': 0.67; '.net,': 0.84; 'low,': 0.84; 'nuts': 0.84; 'subject:Property': 0.84; 'value):': 0.84; 'subject:Abuse': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5YkJkUD3vVExTngpw/3PGYxdbBGjmD+/biXjaP2vAUs=; b=v2d6nZKlPKoTGVq+tSCUY9Pk4dZuc3AaYAl694aBjUswMu+AlXoHA1JRemLIJrCbN+ BYbVpTfVZbA4Y232BtrwF2PoFi0gyVPvUzMfano0aNmYvLRFNi0aRM7NzgJ8Mlbcbf9C L+VikMW5499EyvKheyjW2CZTPytYZpeUPyw7g= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Wed, 14 Dec 2011 09:27:35 -0700 Subject: Re: Property Abuse To: Felipe O Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323880094 news.xs4all.nl 6864 [2001:888:2000:d::a6]:45877 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17221 On Wed, Dec 14, 2011 at 1:28 AM, Felipe O 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