[MATRIX-SIG] random number generator?

Michael McLay mclay@nist.gov
Wed, 29 Oct 1997 12:05:56 -0500


Geoffrey Furnish writes:
 > David J. C. Beach writes:
 >  > > PPS: Is there really no += operator in Python?
 >  > 
 >  > Yup, no += operator.  Python's designers (Guido and others) opted not to
 >  > use many of the "fancy" operators from c and c++ that make it so easy to
 >  > get yourself in trouble...  Among these, +=, -=, *=, /=, ++, and --.
 >  > 
 >  > One might argue that writing a=a+1 is a bit more work than writing a+=1
 >  > or a++, but then again, Python is a whole lot easier to read and is more
 >  > consistent (IMHO) than either c or c++.  Having more operators is not
 >  > necessiarly a good thing.
 > 
 > Speed is the most important counter argument, imo, and one which ought
 > to be of considerable concern to NumPy customers.  I have previously
 > done timing tests between loops containing expressions like:
 > 
 > 	a[i] = a[i] + x[i];
 > 
 > versus
 > 
 > 	a[i] += x[i]; 
 > 
 > in C and C++.  The += form was as much as 20% faster on some tests on
 > some architectures.

Couldn't the performance also be gained by optimizing the parser to
recognize this idium and avoided making the temporary variable?

The syntax addition has been brought up before.  Didn't Guido say he
would consider adding the patches if someone did the work of writing
the code for +=, -=, *=, and /= to the language.  It's not his
priority so someone else needs to become inspired.  I think the ++ and
-- operators sould be avoided.

 > Frankly, for a language litered with "self." on nearly every line, it
 > is very hard for me to buy that "a = a + 1" is syntactically more
 > beautiful.  It certainly is slower.

It is not a matter of beauty, but clarity.  a += 1 is familiar
notation to C programmers, but it may not be immediately apparent what
this statement would mean if you are a Fortran programmers and a
non-programming who is using Python for scripting.  It also borders on
feature creep.  I tried searching for += in the mail archive and I
wasn't able to locate relevant message because the usual problem of
using symbols instead of names.


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________