I was teaching a class in Test Driven Development (TDD) a few weeks ago and I learned this new phrase, “Refrigerator Code.”
When I teach TDD, I teach the development cycle as:
- . Write a test or a piece of one.
- . Get the test to compile but still fail.
- . Make the test pass.
- . Make the code resume quality.
- . Repeat.
Step 4 requires explanation. Resume quality means that once I get the test passing, I want my code to be so good that I’m willing to take it out on a job interview as an example of my best work. This code would follow the rules of Simple Design, that is:
- . All the tests pass.
- . There is no duplication in either the code or in the tests.
- . It expresses my intent.
- . It minimizes the number of methods and classes.
I believe all code written via TDD should be the best code that I’m able to write. There’s really no excuse other than laziness for leaving your code sloppy or hard to understand when it is written using TDD.
One of my students used the phrase Refrigerator Code to describe what I was talking about. What’s that? It’s code that you’re so proud of that you want to take it home and hang it on the refrigerator, right alongside of your children’s drawings. I love it.
So from now on, I am committed to only writing Refrigerator Code.
I like it. Refrigerator code is cool and it stays fresh longer. :) I do like that feeling, that feeling you get when you realize you've made something really cool and you'd like to show it off. Everyone should have that.
I like it too ! In fact, that's what software craftsmanship is about : creating a quality product both for the customer (external quality, guaranteed by the tests) and for your fellow craftsmen (elegant, understandable code). Something that you can be proud of.
Definitely a more easily palatable term than my term: Code Naked. :-)
Add Child Page to RefrigeratorCode