|
|
|
|
|
by ossobuco
493 days ago
|
|
> No, not in the face of any sort of concurrency it doesn't... I fail to see how does that relate to the article in question. The author provided an example for which counter() works well, he didn't claim that the same "pattern" would be good for 100% of the use cases. |
|
If you want to do this (and you shouldn't, because global state is bad for 14 other reasons), at the very least, make it thread safe and not trivially overflowing:
(the 1+ is because the original author used pre-increment instead of post-increment)Like, this is not awesome, and you shouldn't do it, but it's at least not a total disaster.
EDIT: actually, this is also bad, because the `prv_counter` is not really private at all. The better way to do that would be:
Three different serious issues in two lines of code, fun!