process starts by writing tests that give you confidence to change the code. And it turns out there’s no better way to learn how unfamiliar code works than to write a learnin test—a test that pokes and prods existing code to tease out how it works. You learn what the code does—and doesn't do—by actually using it in a safe context. Each new thing you learn about the code is recorded in an automated test, until finally you end up with a suite of regression tests that represent your knowledge base about the code.
Then, in the safety of a suite of good tests, refactor and reformat the code as you read through it. For example, when you understand what a chunk of code does, refactor it into a well-named method. Little by little, as you codify your understanding through refactorings, the code itself improves.
Making Good Code
I hope you've enjoyed this series as we've covered several craft techniques for improving the internal quality of code so that it responds to change quickly. Rather than attempting to condense all that into a summary, I thought I'd leave you with a general recipe that has helped me improve my coding craft:
- Write lots of code—because becoming good at any craft takes a lot of practice.
- Share your code with your peers to get a broad spectrum of feedback.
- Constructively critique code written by others to learn new ways of doing things.
And above all else, have fun! If you're passionate about writing code, then it should always be enjoyable. This is your craft.
|Staying Out of Code Debt||133.77 KB|