A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/079738.html below:

With or Using

With or UsingMichael Hudson mwh21 at cam.ac.uk
Mon Apr 30 04:09:00 EDT 2001
"Delaney, Timothy" <tdelaney at avaya.com> writes:

> > Of course, augmented assignment was made for situations where 
> > you would like
> > to avoid writing

Nah, augmented assigment was made so that I could write:

    x += 1

inside loops and such <0.5 wink>.  Semi-seriously, I like it because
it allows me to say "add 1 to x" rather than "set x to the value of x
plus 1", and as the former is what I usually *mean*, to me it's a win.
 
> >     a.b.c().d[4].e.f.g.h().k = a.b.c().d[4].e.f.g.h().k + 1
> > 
> > allowing you instead to write
> > 
> >     a.b.c().d[4].e.f.g.h().k += 1
> 
> I am of course aware that the above is using silly made-up expressions, but
> they raise an important point.
>
> Both of the above may actually have different semantics. In each case you
> have a large number of function calls (remember, each class attribute access
> can be a function call ...). If any one of those calls returns a different
> object to the previous invocation, the two verions may be semantically
> different. In this case, binding to a temporary may be the wrong thing to do
> (or at least less of the expression should be bound to the temporary).

This is true.  OTOH, if you write 

    a.b.c().d[4].e.f.g.h().k = a.b.c().d[4].e.f.g.h().k + 1

and *don't* mean something fundamentally similar to

    a.b.c().d[4].e.f.g.h().k += 1

then you have problems all of your own.

Cheers,
M.

-- 
  I've even been known to get Marmite *near* my mouth -- but never
  actually in it yet.  Vegamite is right out.
UnicodeError: ASCII unpalatable error: vegamite found, ham expected
                                       -- Tim Peters, comp.lang.python

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4