|
|
|
|
|
by louthy
3367 days ago
|
|
I find this to be a really poor argument. Essentially you're lucky if your systems continue to work as others go off changing message formats without consideration for the code that will receive it? On a suitably complex/large system this is a recipe for disaster. Things start to slowly rot. It is far better to maintain the old function, accepting the old struct, map it to the new struct and forward it on to the new function that accepts the new struct. Let the old one consume anything that's already queued, or being sent from other nodes that haven't yet been upgraded whilst the new one takes the new format. |
|
To achieve that, we follow the design of Protocol Buffers:
1) Each field in each struct has both a name and a numeric id. Only ids are used for serialization, so field names can be changed at any time.
2) All fields are marked as optional or repeated, never required. Most code is written to handle missing fields gracefully.
3) Changing the type or id of an existing field is forbidden. (Note that changing the contents of a nested struct doesn't count as changing its type.)
4) Adding a new field is okay, as long as you use an id that was never used before. (Each struct definition has a comment indicating the next available id to use.)
5) Removing a field is okay if you've checked that no one is using it anymore.
6) As a small but intentional bonus, you can change an optional field to repeated while preserving binary compatibility.
In the end it works out. You can think of breakages that could theoretically happen, but they don't.