On 2012-11-14 14:30:19 +0000, Timon Gehr <[email protected]> said:
On 11/14/2012 01:42 PM, Michel Fortin wrote:
On 2012-11-14 10:30:46 +0000, Timon Gehr <[email protected]> said:
So do I. A thread-local static variable does not imply global state.
(The execution stack is static.) Eg. in a few cases it is sensible to
use static variables as implicit arguments to avoid having to pass
them around by copying them all over the execution stack.
private int x = 0;
int foo(){
int xold = x;
scope(exit) x = xold;
x = new_value;
bar(); // reads x
return baz(); // reads x
}
I'd consider that poor style.
I'd consider this a poor statement to make. Universally quantified
assertions require more rigorous justification.
Indeed. There's not enough context to judge fairly. I can accept the
idea there are situations where it is really inconvenient or impossible
to pass the state as an argument.
That said, I disagree that this is not using global state. It might not
be globally accessible (because x is private), but the state still
exists globally since variable x exists in all threads irrespective of
whether they use foo or not.
If done in such a way that it makes refactoring error prone, it is to
be considered poor style.
I guess we agree.
--
Michel Fortin
[email protected]
http://michelf.ca/