Serialization + semantics of toString

aarti_pl aarti at interia.pl
Sun Nov 15 14:47:43 PST 2009


aarti_pl pisze:
> Andrei Alexandrescu Wrote:
>> aarti_pl wrote:
>>> I forgot to throw a link:
>>> http://www.dsource.org/projects/doost/browser/trunk/examples/util/serializer/FunctionTest.d 
>> Cool, do you also have documentation?
>> Andrei
> 
> Well, that's definitely weak point of this library. :-) 
> You can find some information on doost wiki: 
> http://www.dsource.org/projects/doost/wiki
> There are also some DDOC comments in code. It's also worthy to look on Boost serialization library description, as my library is based on it.
> Anyway I will try to improve documentation a bit during weekend.
> Additionally I would like to mention that there is also great BinaryArchive from Bill Baxter, which I didn't mention in my first post.
> ---
> I think that the most interesting question is if we can replace toString() with template based solution? So instead of:
> String toString()
> 
> we would write e.g.:
> void describe(T)(T archive) {
> }
> 
> Some other things should be considered:
> * What about virtual calls to describe? Currently template methods are not virtual, but I remember that there were posts that it is possible in some limited way.
> * Is it semantically same solution as toString()? Or toString() is used for something other than describing members of class? 
> * If toString() is used for other things than describing class/struct fields, then do we need a standard way to do this or should it be implementation specific?
> * Solution with template method seems to be more general, as there might be different customization of output for every kind of archive, but isn't it too much for simple uses? Maybe string output is just enough?
> * Should be there some default archive available or should it be always defined by user?
> 
> Best Regards
> Marcin Kuszczak
> (aarti_pl)

I have put some more user documentation on Doost project wiki, but it is 
not yet half finished. Nevertheless I think it should help to start 
working with serializer.

I am especially interested about comments on Storage concept. I am 
completely unsure if this design is good enough. Comments might be send 
privately: aarti_no_spam_[at]interia.pl or here on NG.

----

After thinking a bit about toString/serialization I got to conclusion 
that these two are different things. In my opinion the best way to 
proceed would be to change name of toString method into:
toDebugString();
as it discourages using it for anything other than debugging. Default 
implementation of toDebugString() should be serialization of object to 
string.

It just occurred to me that it dosn't make any sense to add special 
serialization code (even if it is simple) to just get quick and dirty 
printout of object state. These are just two different use cases.

Best Regards
Marcin Kuszczak
(aarti_pl)



More information about the Digitalmars-d mailing list