On 06/07/2010 03:40 PM, Scott Carey wrote:
If the specific compiler generated a couple constructors --
* A default empty argument constructor -- fills fields with defaults.
* A constructor with all fields passed in -- assigns fields from the 
constructor and does nothing with defaults.

Then I can use the latter to avoid the performance issue.

A problem with the latter is that such constructors can be fragile. If you have a number of integer fields and reorder them in your schema then the geneated constructor arguments will be re-ordered but the compiler will not notice a problem.

Another option might be to have a flag on the compiler to control generation of default value settings.

FWIW, I have written wrappers around all of my datum classes to deal
with this,

FWIW, Philip claims that (from his Google experience with protobufs) that the best practice is always to use a manually-written wrapper around generated classes.

and I have wanted to either modify the SpecificCompiler or
have a new generated object 'flavor' that had the safe-construction,
union resolution, and getter methods that my wrappers provide.  I
just haven't had time and its lower priority than some other
enhancements I'll need soon.

Perhaps you can just post some pseudo code that illustrates what would be generated, for discussion?

For generated code like this I see no point to getter/setter methods. They seem equivalent to public fields. But perhaps I'm missing something.

Doug

Reply via email to