On 04/16/2012 08:42 PM, Jacob Carlborg wrote:
On 2012-04-16 18:53, Walter Bright wrote:
On 4/16/2012 9:40 AM, Jacob Carlborg wrote:
Regardless of how the runtime reflection is generated, by a library or
the
compiler, it needs to be available to all types.

Why?

(I can see the point for a dynamic language, but not a static one.)

The standard example that comes back is serialization. That can be done
without support for runtime reflection but not as good as with the
support. As far as I know it's impossible to serialize through a base
class reference without registering the subtype with the serializer, if
runtime reflection isn't available.


This could be fixed by introducing a simple language feature that allows a supertype to specify mixin templates that are 'inherited' by all subtypes.

Eg:

interface ISerializable {
    ubyte[] serialize();

    super mixin Serialize;
}

class A: ISerializable {
    int x;
    int y;
}

class B: A{
    A foo;
    @nonserialized B cache;
}

Would be lowered to:

interface ISerializable {
    ubyte[] serialize();

    mixin Serialize;
}

class A: ISerializable {
    int x;
    int y;

    mixin Serialize;
}

class B: A{
    A foo;
    @nonserialized B cache;

    mixin Serialize;
}

This way, all subclasses automatically register themselves.

I think this would be very useful in general. I often do this manually.

Reply via email to