May 13th, 2024

Before you try to change something, make sure you can change nothing

Some time ago, I recommended that before you try to do something, you should make sure you can do nothing. There’s a variation of this maxim when you are adding code to an existing component rather than writing something from scratch: Before you try to change something, make sure you can change nothing at all.

In other words, take the existing component and run it before making any changes to it at all. Does it work?

Sometimes we’ll get questions from developers saying, “All I did was add this line of code, and I’m getting all these build errors. What did I forget? Do I need to add another dependency?” This often triggers a prolonged troubleshooting session trying to see how that line of code could result in those build errors, until somebody asks, “Did it build before you made any changes?” And then we learn, “Oh, I don’t know. I never tried.”

This step of building the unchanged component (perhaps I should call it “step negative one”) makes sure that your development environment is properly set up: Are the build tools installed? Are the correct build tools installed? Did you install all the necessary libraries? Maybe the component retrieves a NuGet package from a NuGet feed: Can you authenticate to that feed?

After you build the component, can you deploy and run it? Did you set your test system into an appropriate developer mode so you can install your component onto it? Do the unit tests pass?

After you’ve gained comfort with a component, you can start skipping these steps, but these are important steps to undertake before writing a single line of code: If you can’t get the component to build, deploy, and run as-is, you’ll certainly never get it to do those things after you make your changes!

And doing all this on an unchanged project makes it clear that the problems you’re encountering are unrelated to any changes you plan on making. Now you know that you need to troubleshoot how you set up your development environment, rather than debugging your code.

Bonus chatter: If you’re particularly unlucky, the problem will be that the project is already broken and nobody noticed. But at least you can get the attention of the people with primary responsibility for the project, seeing as you can clearly show that the problem is theirs and not yours.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • pnoop star

    You looked at their code so now the problem is yours anyhow.

  • Clockwork-Muse

    …. and this is why I really like devcontainers. Because generally it allows you to encapsulate almost all of the environment in a deployment package, making setup for other programmers much easier.