Multi-dimensional list initialization

rusi rustompmody at gmail.com
Fri Nov 9 16:05:37 CET 2012


On Nov 9, 11:37 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Fri, 09 Nov 2012 17:07:09 +1100, Chris Angelico wrote:
> > On Fri, Nov 9, 2012 at 12:39 PM, Mark Lawrence <breamore... at yahoo.co.uk>
> > wrote:
> >> On 07/11/2012 01:55, Steven D'Aprano wrote:
>
> >>> Who knows? Who cares? Nobody does:
>
> >>> n -= n
>
> >> But I've seen this scattered through code:
>
> >> x := x - x - x
>
> > Can you enlighten us as to how this is better than either:
> >  x := -x
> > or
> >  x := 0 - x
> > ? I'm not seeing it.
>
> I'm hoping that Mark intended it as an example of crappy code he has
> spotted in some other language rather than a counter-example of something
> you would do.
>
> To be pedantic... there may very well be some (rare) cases where you
> actually do want x -= x rather than just x = 0. Consider the case where x
> could be an INF or NAN. Then x -= x should give x = NAN rather than zero.
> That may be desirable in some cases.

In x86 assembler
mov ax, 0
is 4 bytes
sub ax, ax
is 2
and therefore better (at least for those brought up on Peter Norton);
the most common being
xor ax, ax


More information about the Python-list mailing list