Coding style and Python versions (was Re: Another itertool function?)
donn at u.washington.edu
Mon Apr 28 19:22:14 CEST 2003
Quoth aahz at pythoncraft.com (Aahz):
| In article <zAara.22169$K35.739509 at news2.tin.it>,
| Alex Martelli <aleax at aleax.it> wrote:
|> Aahz wrote:
|>> In article <b8hc64$6n2$1 at slb9.atl.mindspring.net>,
|>> Andrew Dalke <adalke at mindspring.com> wrote:
|>>> i = i + 1
|>> I'm a little curious why you didn't write this as
|>> i += 1
|>> Any reason (i.e. still need to support 1.5.2) or just habit? If the
|>> latter, why haven't you changed your habit?
|> There is no special reason to "change that habit", e.g. not performance:
|> No statistically significant / measurable difference. The tiny difference
|> in conciseness is hardly compelling one way or another, either.
| However, I do think the difference in readability is somewhat compelling.
| Using augmented assignment, I can think to myself, "Ah, this is mutating
| an object." (This aside from the fact that numbers can't actually be
| mutated -- it's a convenient mental shorthand.)
Hm, so strictly speaking, you can think to yourself, ``ah, this may
be mutating an object, depending on the implementation.'' Readability
doesn't seem very compelling here, since the point is ambiguous.
Maybe to avoid confusion one should never use augmented assignment
at all, and invoke a method instead when the intent is to mutate.
Donn Cave, donn at u.washington.edu
More information about the Python-list