LinqToStdf
LinqToStdf copied to clipboard
Discussion about derived and coupled fields
When I started doing reconciliation of the current codebases, I started adding tests to keep from breaking things. I took a simple naïve approach, that every record should be able to be round-tripped through writing and reading intact. I picked two states to start with for most records:
- Empty
- Last field populated
For many records, this works find, and stresses the trickiest corners of the code... the optional/missing contingencies. There were several known problems with this approach like bugs in the encoding would be reflected in decoding and cancel out, but there was a problem that I didn't appreciate fully being years removed from the project and the context surrounding it.
STDF fields are coupled in complicated ways.
Our approach always worked well for reading, and was "good enough" for writing if you were thorough. The 2 extreme positions are:
- Force the developer to be thorough
- "Fix" everything
A prime example is a Ptr. It would be nice to say:
var ptr = new Ptr
{
Result = 4.95f,
Pass = true,
}
And then have it pass merrily into a file and be valid.
Unfortunately, Ptr has lots of flags and such, and we don't have a good way of doing all the mappings. We currently expose the raw flags AND the "valid" states in the object model, and therefore they can conflict.
I'd love to be in a place where everything is fixed up and you can't get into a consistent state, but I don't think we have the right mechanisms for that today.
Options:
- Do nothing. This roughly equates to good reading experience, and rough writing experience.
- Add consistency errors on write
- Add "virtual" fields whose data derives from the flags, etc., and do away with all the existing hybrid states.
- This is similar to the opt_flag fields we have now, except that its data would ONLY come from the flags.
- It's likely that there are cases where we could still be inconsistent (one flag controls 2 fields)
- These could probably give good errors on write instead of weird data.