DIP 45 - approval discussion

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Nov 13 10:41:36 PST 2013


13-Nov-2013 13:27, Andrei Alexandrescu пишет:
> On 11/13/13 12:55 AM, Jacob Carlborg wrote:
>> On 2013-11-13 05:07, Andrei Alexandrescu wrote:
>>
>>> Then how do you figure doing this:
>>>
>>> class Streamable { ... }
>>> class Foo : Streamable { ... }
>>> class Bar : Streamable { ... }
>>> string className = stream.readln();
>>> Streamable obj = ...;
>>>
>>> How do you create obj from className, when className could be either
>>> "Foo" or "Bar"? In the general case there could be any number of
>>> classes, in different modules.
>>
>> This requires Object.factory (or equivalent) and that all subclasses
>> have been registered as well.
>
> With Object.factory that's taken care of already.

I have to chime in.

Serialization != calling default constructor by name.
You have to work out fields somehow - Object.factory doesn't help with 
that. What serialization needs is some hook - be it delegete or whatnot:

Object deserialize(SomeStreamingAbstraction here);

Simply snatching a name is not serialization. Not to mention that far 
too many protocols are not text.

Keeping built-in map of class-name --> "create via default constructor"
is an awful example of ONE SIZE FITS ALL. It doesn't!

Simply on the ground of "solves problem in too narrow scope for a hefty 
coast to the user" I'd drop it.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list