[RFC] Object Serialization

kris foo at bar.com
Sun Mar 18 23:08:15 PDT 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



More information about the Digitalmars-d mailing list