attributes, properties, and accessors -- philosophy
Chris Rebert
clp2 at rebertia.com
Mon Nov 23 14:06:14 EST 2009
On Mon, Nov 23, 2009 at 10:52 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> The problem I have with properties is my typing. I'll end up assigning to
> an attribute, but get the spelling slightly wrong (capitalized, or missing
> an underscore -- non-obvious things when bug-hunting), so now I have an
> extra attribute which of course has zero effect on what I'm trying to do and
> I start getting wierd results like viewing deleted records when I *know* I
> set useDeleted = False... 30 minutes later I notice it was /supposed/ to be
> use_deleted. *sigh*
>
> So -- to keep myself out of trouble -- I have started coding such things as,
> for example:
>
> result = table.use_deleted() # returns True or False
> table.use_deleted(False) # skip deleted records
>
> instead of
>
> result = table.use_deleted
> table.use_deleted = False
>
> My question: is this [ severely | mildly | not at all ] un-pythonic?
Yes, it's unpythonic. Use something like pychecker, pylint, or
pyflakes, which will catch the sorts of typo errors you talk about.
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list