thermoplastics
@thermoplastics
10 years ago
Static variablesstatic variables

Stuart Kearney
@stukearney
13 years ago

Static variables - by definition - causes pieces of program state to persist, however this often creates undesirable behavior. Outside of certain very specific situations (for example, keeping track of the number of times a function has been run), this persistence tends to create unpredictable behavior. Unit tests are supposed to be completely independent of each other; a single test's failure (or not being run) should under most circumstances not cause other tests to fail. When static variables are involved in code covered by unit tests, it becomes very easy to rely on one test passing without realizing it. Should that test start failing because of a code change, it's likely that other unrelated tests will also start failing despite being completely unrelated to that change. An example of this is having a test change a static configuration variable and resetting it at the end of the test - if the test fails, it may not be able to reset to the original value and as a result all other tests expecting that value will also start to fail.

Eric Stern
@eric.stern
13 years ago

Can easily cause bugs. Especially when your function callStatic variables - by definition - causes pieces of program state to persist, however this often creates undesirable behavior. Outside of certain very specific situations (for example, keeping track of the number of times a function which calls ithas been run), this persistence tends to create unpredictable behavior.

rework overview with some more detail that will lead into other sub-points

undefinedurl nextprice drop