Versioning problem
The Versioning Problem
Here's the problem:
- You're going to keep making changes as you find bugs.
- Some people aren't going to get your new code right away.
- And even when they do get your new code, it has to run against old data anyway.
Welcome to the versioning problem.
There is a solution, and it's a solution that's been rediscovered countless times. Let me document it here.
Backwards Compatible vs. Backwards Incompatible
The first thing you have to think about is whether the change is backwards compatible.
"Backwards Compatible" means that the new code can run with old data and nothing changes. You might get some new features, but all the old stuff works exactly the way it used to work.
"Backwards Incompatible" means that the new code does not run with old data the same way the old code ran.
You will often want to make backwards incompatible changes. However, the first key of solving the versioning problem is to NEVER make backwards incompatible changes.
If you want to make a backwards incompatible change, you have to make two backwards compatible changes.
- The first change introduces the new fields in your data. This code can read the old data and the new data and converts the old into new.
- The second change drops the old data. It can no longer read the old data but only uses the new. This change is backwards incompatible with the previous version of the data.
Provided that the user applies the upgrade in the right sequence, they should be able to keep using the code without any changes on their part.