Bug or feature?

Jp Calderone exarkun at intarweb.us
Fri Jan 16 14:18:53 EST 2004


On Fri, Jan 16, 2004 at 04:13:06PM +0000, James Henderson wrote:
> On Friday 16 January 2004 2:44 pm, Alexey Nezhdanov wrote:
> <snip>
> > I know the case where such python behaivoir causes hard-to-catch problems.
> > I do not know any case (anybody knows? please give example) where such
> > "feature" may be useful.
> >
> > So I proposing to make a change into python and reverse the order of
> > calculations.
> > Just for sure:
> > === Order used now ===
> > ## a+=a.Sub(b)
> > 1. evaluate value of 'a'
> > 2. evaluate value of 'a.Sub(b)'
> > 3. evaluate the sum
> > 4. store the result into 'a'
> > === Proposed order ===
> > ## a+=a.Sub(b)
> > 1. evaluate value of 'a.Sub(b)'
> > 2. evaluate value of 'a'
> > 3. evaluate the sum
> > 4. store the result into 'a'
> 
> -1
> In any language that uses such an operator I would expect:
> 
> a += b
> 
> to be synonymous with:
> 
> a = a + b

  Of course, it should be noted that, in Python, "a += b" is only sometimes
synonymous with "a = a + b".  The rest of the time, it's hard to say what it
is synonymous with :)

> 
> You are suggesting that it should mean:
> 
> a = b + a
> 
> It is not like Python to attach its own idiosyncratic semantics to operators 
> already well known from other languages.  I think this would catch a lot of 
> people out.
> 

  Definitely.  Consider tuple += tuple.  It would not only be idiosyncratic,
but outright surprising and irrational if using += on (1, 2) and (3, 4)
resulted in (3, 4, 1, 2).

> Of course, it's probably best to avoid writing code where the order makes a 
> difference. :)

  Amen.  Write simple code and all those who follow in your footsteps will
thank you.

  Jp




More information about the Python-list mailing list