PostDoc should work similarly to FromDoc
grahamboree opened this issue · 1 comments
grahamboree commented
Currently PostDoc needs to be a public Func that's set on an instance of an object like so:
class Ship {
public System.Func<Ship, Ship> PostDoc = (d) => {
// ...
return d;
};
}
whereas FromDoc is a public static method that operates similarly:
class Ship {
public static Ship FromDoc(Ship existing, DocNode doc) {
// ...
return existing;
}
}
There's a few issues with the PostDoc style:
- Different coding styles between PostDoc and FromDoc make it harder to get them right
- Doesn't work well with inheritance
- Adds executable bloat (many Func type instances)
- Runtime cpu cost and heap fragmentation (bigger issue) from generating a new lambda for every instance of every class with a PostDoc
With these considerations, I think it seems to make sense to author PostDoc like FromDoc:
class Ship {
public Ship PostDoc(Ship existing) {
// ...
return existing;
};
}
rdw commented
+1
I think it's really only used in the demo, as currently written.