Dylan Smith

Linked: Too DRY - The Grep Test (Jamie Wong)

http://jamie-wong.com/2013/07/12/grep-test/

The Grep Test: If any code declares or makes use of a function, class, module, or variable that cannot be located by grepping for its full identifying token, it fails the Grep Test.

When modifying existing code, especially without good test coverage, especially when refactoring code without good test coverage, it’s essential to be able to find all the usages of a given class or function. Here, grep is my tool of choice. Dynamic invocation ruins this. If you have code breaking the Grep Test, refactoring becomes a nightmare. I’ve deleted code I thought was unused far too many times because of this.

This is particularly relevant as I work on a lot of CSS refactoring and retirement this year. In a perfect world, I can search for a class name, check it’s not used in markup, and remove the styles. But sometimes classes are generated dynamically and it causes headaches. (This is also a selling point for verbose naming conventions like BEM.)

As an aside, in the fast-paced web dev world of 2021, I love finding a nine year old article that feels like it could have been written yesterday.

Newer JOFA Helmets Older Resolutions