On 09/11/2012 06:37, Steven D'Aprano 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...@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.
Correct, CORAL 66 and pointed out to me by a colleague when another team
member had resigned.
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.
Interesting what comes up when we get chatting here. I hope we don't
get punished for going off topic :)
At the very least, the compiler should NOT optimize away x = x - x to
x = 0 if x could be a float, complex or Decimal.
X was an int so almost certainly optimised away by the SDL compiler on
VMS of 1986 or 1987.
--
Cheers.
Mark Lawrence.
--
http://mail.python.org/mailman/listinfo/python-list