[Haskell-cafe] How to avoid keeping old data formats in your code?
qdunkan at gmail.com
Sun Dec 21 00:50:22 UTC 2014
On Sat, Dec 20, 2014 at 3:29 AM, Corentin Dupont
<corentin.dupont at gmail.com> wrote:
> I didn't had so much luck with this question. The question was:
> -> "How to avoid keeping old data formats in your code?"
> Indeed those old data formats are often needed for retro-compatibility with
> previous versions of your software.
> Say you have a data structure that is serialized in a file, and then you add
> a field in a later version. You are obliged to keep both versions of the
> data structure if you want to be able to read both versions of the file.
> Potentially, if you update very often your structure between releases, you
> are obliged to keep N versions of the data structure in your code.
> See the exemple at: http://acid-state.seize.it/safecopy
I just keep both versions. It doesn't seem like too much hassle. I
move the old version to the Serialize module so modules that aren't
concerned with serialization aren't cluttered.
In the fully general case, I think there's no way around it. But if
you are just adding a field, or or changing a field to a super-type
(e.g. 'a' becomes 'Maybe a') then you can trivially upgrade in place
in the deserialization code. Or you can use something like protobufs,
which supports that kind of thing automatically.
More information about the Haskell-Cafe