April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Tue, 17 Apr 2012 02:50:02 -0400, Jacob Carlborg <doob@me.com> wrote:
> On 2012-04-17 08:33, Walter Bright wrote:
>> On 4/16/2012 11:26 PM, Jacob Carlborg wrote:
>>> Then it won't be possible to serialize third party types if they don't
>>> implements ISerializable. In this case, this solution is no better
>>> then manually
>>> registering types. Actually it's worse, since I can manually register
>>> third
>>> party types.
>>
>> I'm not so sure in D that you can serialize arbitrary types without them
>> designed to be serializable. For example, what will you do with unions?
>> Pointers to global data?
>
> Not all types are serializable of course. For those types you would have to register a function or similar. But most other types are possible to automatically serialize. I don't see a point in making them less serializable by requiring to implement an interface. I also think mostly one would want to serialize objects or an hierarchy of objects.
Can you explain why .NET types are not by default serializable? All of them have full runtime reflection AFAIK.
I'm not using that as an argument, I'm genuinely interested.
-Steve
|
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 2012-04-18 03:11, Nick Sabalausky wrote: > Can't you just query compile-time information to see what classes inherit > from Base? Then you could just try downcasting to them. Is that possible? -- /Jacob Carlborg |
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michal Minich | On 2012-04-18 12:37, Michal Minich wrote: > On Wednesday, 18 April 2012 at 10:07:59 UTC, Robert Clipsham wrote: >> // a.d >> class Base { /* whatever magic to get derived classes */ } >> // b.d >> import a; >> class Derived : Base {} >> void main() {} > > to find derived classes at runtime: > http://forum.dlang.org/thread/mailman.1052.1292505452.21107.digitalmars-d-learn@puremagic.com#post-op.vns7nfjpvxi10f:40biotronic-pc.lan > But you can't get the fields of an object at runtime. Again, hence the need for proper runtime reflection. -- /Jacob Carlborg |
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2012-04-18 13:06, Steven Schveighoffer wrote: > On Tue, 17 Apr 2012 02:50:02 -0400, Jacob Carlborg <doob@me.com> wrote: > Can you explain why .NET types are not by default serializable? All of > them have full runtime reflection AFAIK. > > I'm not using that as an argument, I'm genuinely interested. I'm wondering that as well. -- /Jacob Carlborg |
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 18/04/2012 17:31, Jacob Carlborg wrote: > On 2012-04-18 13:06, Steven Schveighoffer wrote: >> On Tue, 17 Apr 2012 02:50:02 -0400, Jacob Carlborg <doob@me.com> wrote: > >> Can you explain why .NET types are not by default serializable? All of >> them have full runtime reflection AFAIK. >> >> I'm not using that as an argument, I'm genuinely interested. > > I'm wondering that as well. > From my quick google I couldn't find a definitive answer, but: http://stackoverflow.com/questions/4408909/why-classes-are-not-serializable-by-default-in-net http://en.wikipedia.org/wiki/Serialization (reasons listed under Java) -- Robert http://octarineparrot.com/ |
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Wed, 18 Apr 2012 09:59:10 -0400, Jacob Carlborg <doob@me.com> wrote:
> On 2012-04-18 03:11, Nick Sabalausky wrote:
>> Can't you just query compile-time information to see what classes inherit
>> from Base? Then you could just try downcasting to them.
>
> Is that possible?
No. Not from within a template that doesn't know about those classes (which presumably your serialization function is).
-Steve
|
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Clipsham | On Wed, 18 Apr 2012 13:18:20 -0400, Robert Clipsham <robert@octarineparrot.com> wrote:
> On 18/04/2012 17:31, Jacob Carlborg wrote:
>> On 2012-04-18 13:06, Steven Schveighoffer wrote:
>>> On Tue, 17 Apr 2012 02:50:02 -0400, Jacob Carlborg <doob@me.com> wrote:
>>
>>> Can you explain why .NET types are not by default serializable? All of
>>> them have full runtime reflection AFAIK.
>>>
>>> I'm not using that as an argument, I'm genuinely interested.
>>
>> I'm wondering that as well.
>>
>
> From my quick google I couldn't find a definitive answer, but:
>
> http://stackoverflow.com/questions/4408909/why-classes-are-not-serializable-by-default-in-net
>
> http://en.wikipedia.org/wiki/Serialization (reasons listed under Java)
I think those answer the question quite well.
In summary, just because you *can* serialize a type doesn't mean you *should*, and the risks of serializing something that shouldn't be serialized trumps the convenience of not having to mark it. The latter part is really a subjective statement, but I would agree with it.
I bet part of the confusion comes from the fact that such attributes are named "Serializable", whereas pretty much anything is serializable. It should be something more along the lines of "AllowSerialization"
-Steve
|
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2012-04-18 19:36, Steven Schveighoffer wrote: > On Wed, 18 Apr 2012 13:18:20 -0400, Robert Clipsham >> From my quick google I couldn't find a definitive answer, but: >> >> http://stackoverflow.com/questions/4408909/why-classes-are-not-serializable-by-default-in-net >> >> >> http://en.wikipedia.org/wiki/Serialization (reasons listed under Java) > > I think those answer the question quite well. > > In summary, just because you *can* serialize a type doesn't mean you > *should*, and the risks of serializing something that shouldn't be > serialized trumps the convenience of not having to mark it. The latter > part is really a subjective statement, but I would agree with it. I suspected something like that. > I bet part of the confusion comes from the fact that such attributes are > named "Serializable", whereas pretty much anything is serializable. It > should be something more along the lines of "AllowSerialization" > > -Steve -- /Jacob Carlborg |
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 4/18/2012 10:20 AM, Steven Schveighoffer wrote:
> On Wed, 18 Apr 2012 09:59:10 -0400, Jacob Carlborg <doob@me.com> wrote:
>
>> On 2012-04-18 03:11, Nick Sabalausky wrote:
>>> Can't you just query compile-time information to see what classes inherit
>>> from Base? Then you could just try downcasting to them.
>>
>> Is that possible?
>
> No. Not from within a template that doesn't know about those classes (which
> presumably your serialization function is).
>
> -Steve
You can get a list of classes in the executable at runtime from:
foreach (m; ModuleInfo)
{
if (m)
//writefln("module %s, %d", m.name, m.localClasses.length);
foreach (c; m.localClasses)
{
writefln("\tclass %s", c.name);
}
}
|
April 18, 2012 Re: compiler support added for precise GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 4/18/2012 1:19 AM, Walter Bright wrote:
> On 4/16/2012 1:54 PM, Steven Schveighoffer wrote:
>> On Mon, 16 Apr 2012 16:52:54 -0400, Steven Schveighoffer <schveiguy@yahoo.com>
>> wrote:
>>
>>> But we need to change the name early on to avoid conflicts. I don't think a
>>> more generic name would be inappropriate, even if the GC is the only client at
>>> first.
>>
>> Should have said "But we need to change the name early on to avoid confusion
>> later", i.e. "why is this GCInfo template generating reflection info that the GC
>> doesn't use?"
>
>
> Not a bad idea.
Done.
I think it is a worthwhile idea because it leaves the door open for all kinds of information to be generated for types, without needing to modify the compiler at all.
Also incorporated Jacob's suggestion to make it a property.
|
Copyright © 1999-2021 by the D Language Foundation