Thread overview
[RFC] Object Serialization
Mar 18, 2007
Dejan Lekic
Mar 19, 2007
kris
Mar 26, 2007
Graham St Jack
March 18, 2007
These days I am working on object serialization class (and interface) and would like D-brains' comments on following request:

Add a new keyword to D which would enable functionality the "transient" keyword does in JAVA.

I am not a JAVA fan, I have never been, but I just like how elegant JAVA is when it comes to object serialization.

Here is an example how it would "look like":

----------------------------->8------------------------------
class User: Serializable
{
  int id;
  char[] fname;
  char[] sname;
  transient char[] plan;
  // ... methods and constructors here
}

File f = new File("dcommunity.dat", FileMode.Append);
ObjectStream objs = new ObjectStream(f);
User cm = new User(1, "Christopher", "Miller");
objs.writeObject(cm);
objs.flush();
-----------------------------8<------------------------------

The reason behind "transient" keyword is simply to prevent something unimportant from serialization.

After discussion on irc://irc.freenode.org/D IRC channel I have decided to use mixins in order to specify what members are included in serialization - oposite of what "transient" does, because in case of mixin-use it is more clear to specify what should be serialized, than to specify what will not be serialized. :)

I really think adding "transient" keyword would improve D, but I might have overlooked something, that is why I started this thread.

Kind regards

Dejan
March 19, 2007
Dejan Lekic wrote:
> These days I am working on object serialization class (and interface) and would like D-brains' comments on following request:
> 
> Add a new keyword to D which would enable functionality the "transient" keyword does in JAVA.
> 
> I am not a JAVA fan, I have never been, but I just like how elegant JAVA is when it comes to object serialization.
> 
> Here is an example how it would "look like":
> 
> ----------------------------->8------------------------------
> class User: Serializable
> {
>   int id;
>   char[] fname;
>   char[] sname;
>   transient char[] plan;
>   // ... methods and constructors here
> }
> 
> File f = new File("dcommunity.dat", FileMode.Append);
> ObjectStream objs = new ObjectStream(f);
> User cm = new User(1, "Christopher", "Miller");
> objs.writeObject(cm);
> objs.flush();
> -----------------------------8<------------------------------
> 
> The reason behind "transient" keyword is simply to prevent something unimportant from serialization.
> 
> After discussion on irc://irc.freenode.org/D IRC channel I have decided to use mixins in order to specify what members are included in serialization - oposite of what "transient" does, because in case of mixin-use it is more clear to specify what should be serialized, than to specify what will not be serialized. :)
> 
> I really think adding "transient" keyword would improve D, but I might have overlooked something, that is why I started this thread.
> 
> Kind regards
> 
> Dejan

This was one of the principal things Java got wrong in the lib, IMO. The serialization is riddled with special cases, 'secret' method signatures, and overhead up the wazoo. I firmly believe it is entirely the wrong way to go about this, even though it appears simple to apply at first blush

2 cents
March 26, 2007
My own opinion is that things that need to be serialised should be used "just" for serialisation. In D, they would be structs. Trying to have a class fill the needs of internal program logic and serialisation just gets you into trouble.

Once you make this separation, lots of possibilities open up. For
example, you can send "events" between applications when things happen,
and the receiving end applies them to its object model. Some advantages
of this approach are:
* Much less data needs to be transmitted
* The intent of the data transfer is clear
* Observers can be (correctly) advised of the event at the receiving end


kris wrote:
> Dejan Lekic wrote:
>> These days I am working on object serialization class (and interface) and would like D-brains' comments on following request:
>>
>> Add a new keyword to D which would enable functionality the "transient" keyword does in JAVA.
>>
>> I am not a JAVA fan, I have never been, but I just like how elegant JAVA is when it comes to object serialization.
>>
>> Here is an example how it would "look like":
>>
>> ----------------------------->8------------------------------
>> class User: Serializable
>> {
>>   int id;
>>   char[] fname;
>>   char[] sname;
>>   transient char[] plan;
>>   // ... methods and constructors here
>> }
>>
>> File f = new File("dcommunity.dat", FileMode.Append);
>> ObjectStream objs = new ObjectStream(f);
>> User cm = new User(1, "Christopher", "Miller");
>> objs.writeObject(cm);
>> objs.flush();
>> -----------------------------8<------------------------------
>>
>> The reason behind "transient" keyword is simply to prevent something unimportant from serialization.
>>
>> After discussion on irc://irc.freenode.org/D IRC channel I have decided to use mixins in order to specify what members are included in serialization - oposite of what "transient" does, because in case of mixin-use it is more clear to specify what should be serialized, than to specify what will not be serialized. :)
>>
>> I really think adding "transient" keyword would improve D, but I might have overlooked something, that is why I started this thread.
>>
>> Kind regards
>>
>> Dejan
> 
> This was one of the principal things Java got wrong in the lib, IMO. The serialization is riddled with special cases, 'secret' method signatures, and overhead up the wazoo. I firmly believe it is entirely the wrong way to go about this, even though it appears simple to apply at first blush
> 
> 2 cents