Web Refactoring into Testability

In his book Refactoring: Improving the Design of Existing Code, Martin Fowler gives a simple, compelling definition of the word: "noun: a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior". The examples in the book are written in JavaScript and Java. Can the same principles be applied to web development?

In this workshop, Scott Davis (Web Architect and Developer Advocate, ThoughtWorks) explores the idea of refactoring ("improving the design of existing code") through the idea of testability (from Design Patterns Explained: "The correlation of 'testability' to good design can be observed by seeing that code that has weak cohesion, tight coupling, redundancy, and lack of encapsulation is difficult to test.").

Testability, then, isn't reductively the hunt for bugs (e.g. "Unit test all the things!"). Testability is a prism through which we can observe the benefits of our refactoring -- the effectiveness of our design, not just the correctness of our code. If refactoring is our boat, then testability is our rudder. We establish a virtuous cycle between refactoring and testability -- one measures the efficacy of the other, and can also guide us towards further refactorings.