jargon

Comparison

Global mutable statevsHidden dependency

Global mutable state

the test passed alone and failed in the suite, and the difference was something another test had left behind.

State reachable from anywhere and writable by anyone, whether it is spelled as a global variable, a static field or a singleton. It makes execution order significant, makes tests interdependent, makes concurrency unsafe by default, and makes the dependency invisible in every signature. This is what people mean when they call the singleton an anti-pattern: the objection is almost never the instance count.

Full entry →

Hidden dependency

the class needed an environment variable, a file on disk and the current time, and its constructor took nothing.

A dependency a component reaches for without declaring, through a global, a static accessor, an environment lookup or a service locator. The cost is discoverability: you cannot tell what a class needs from its signature, so tests fail with errors about things the test never mentioned. Making them parameters is the whole of the fix, and the resulting long constructor is honest rather than worse.

Full entry →

Related comparisons