why no ++?
Tim Rowe
digitig at cix.co.uk
Sat Aug 4 19:13:00 EDT 2001
In article <3B6A6B97.2060306 at herts.ac.uk>, m.1.robinson at herts.ac.uk (Mark
Robinson) wrote:
> I guess it is perhaps not as clear, but I am not aware of it being a
> common cause of errors in C++ or java (doesn't mean it isn't, just that
> I am not aware of them). I also miss +=, *=, %=, /=, would it really
> make the code that much harder to read/maintain?
It certainly is /a/ source of bugs in C++, and I would expect in Java too.
One infamous one is constructs of the form min(a++, b++).
If min is a function and a and b are distinct, each is incremented once
and the smaller is returned -- probably what is expected.
If min is a function and b is an alias for a then it is incremented twice
and returned. Probably a bug.
If min is a preprocessor macro, it probably expands to something like
(a++)<(b++)?(a++):(b++); now if a and b are distinct both are incremented,
the lesser is returned and is then incremented again -- the value returned
is probably now the value of neither a /nor/ b. If that is intended
behaviour then I hope I never have to maintain your code!
If min is a preprocessor macro and b is an alias for a then it is
incremented twice, returned, then incremented again. Sheesh!
In short, side effects are a Bad Thing!
More information about the Python-list
mailing list