August 22, 2008
Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
> Leandro Lucarella wrote:
> >Don, el 18 de agosto a las 12:41 me escribiste:
> >>I cannot understand the rationale for a toString() member function which doesn't support formatting.
> >I think is useful only for debugging purposes.
> >>C++ got around this by giving state to the iostream classes.
> >I think C++ formatting is heavily ill. All the manipulator stuff is madness.
> 
> It's horrific but surprisingly flexible.  I've created stateful formatters for various protocols and made it work all invisibly with the formatting hooks provided in C++.  For example:
> 
>    std::cout << a << b << c << std::flush;
> 
> The above may perform lazy output of structured XML, some binary encoding, etc. It might be possible to get close with toString, but because it returns an array rather than writing into a buffer some of the flexibiliy (like lazy encoding) would definitely be lost.
> 
> My experience with Java suggests that toString is meant for debugging purposes anyway.  It's rare that an object will produce meaningful user-level output with its toString method.

I agree, I meant that D should do better. Like templates are for gurus in C++ and for people in D, formatting should be for people too in D (as opposed to C++ manipulators =).

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
He cometido pecados, he hecho el mal, he sido víctima de la envidia, el
egoísmo, la ambición, la mentira y la frivolidad, pero siempre he sido
un padre argentino que quiere que su hijo triunfe en la vida.
	-- Ricardo Vaporeso
August 22, 2008
On 2008-08-22 22:10:21 +0200, Leandro Lucarella <llucax@gmail.com> said:

> Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
>> Leandro Lucarella wrote:
>>> Don, el 18 de agosto a las 12:41 me escribiste:
>>>> I cannot understand the rationale for a toString() member function which
>>>> doesn't support formatting.
>>> I think is useful only for debugging purposes.
>>>> C++ got around this by giving state to the iostream classes.
>>> I think C++ formatting is heavily ill. All the manipulator stuff is
>>> madness.
>> 
>> It's horrific but surprisingly flexible.  I've created stateful formatters for
>> various protocols and made it work all invisibly with the formatting hooks
>> provided in C++.  For example:
>> 
>> std::cout << a << b << c << std::flush;

I think that putting formatting details in the stream is a very good idea for serialization, but not for normal textual output, the two things are not the same (even if it might be useful to use some xml serialization for some objects, and send it together with "normal" text).

Fawzi

August 22, 2008
Fawzi Mohamed wrote:
> On 2008-08-22 22:10:21 +0200, Leandro Lucarella <llucax@gmail.com> said:
> 
>> Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
>>> Leandro Lucarella wrote:
>>>> Don, el 18 de agosto a las 12:41 me escribiste:
>>>>> I cannot understand the rationale for a toString() member function which
>>>>> doesn't support formatting.
>>>> I think is useful only for debugging purposes.
>>>>> C++ got around this by giving state to the iostream classes.
>>>> I think C++ formatting is heavily ill. All the manipulator stuff is
>>>> madness.
>>>
>>> It's horrific but surprisingly flexible.  I've created stateful formatters for
>>> various protocols and made it work all invisibly with the formatting hooks
>>> provided in C++.  For example:
>>>
>>> std::cout << a << b << c << std::flush;
> 
> I think that putting formatting details in the stream is a very good idea for serialization, but not for normal textual output, the two things are not the same (even if it might be useful to use some xml serialization for some objects, and send it together with "normal" text).

Yeah, the above example was a simplified version of some pretty fancy stuff I did for a multi-protocol server app.  It made serialization painfully easy for the user (so long as the proper support code was built into the formatting frastructure), but was really operating well beyond the scope of what iostream formatting was intended to do.

In general though I think it's preferable to have such things done differently than raw IO.  Tango has some support for this with its Reader/Writer model in tango.io.protocol, but even that is somewhat limited to specific categories of protocols.  For example, I recently tried using it for ASN.1 transcoding and it just isn't sufficient.


Sean
August 23, 2008
Leandro Lucarella wrote:
> Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
>> My experience with Java suggests that toString is meant for debugging purposes anyway.  It's rare that an object will produce meaningful user-level output with its toString method.
> 
> I agree, I meant that D should do better. Like templates are for gurus in
> C++ and for people in D, formatting should be for people too in D (as
> opposed to C++ manipulators =).

I strongly favor library solutions over language solutions for this. Even if there were a language solution, I would still want a library solution so I could better enforce separation of concerns. Unless I want to use dependency injection on my domain classes, which is an Abomination unto Nuggan, or put complex formatting logic into them, which is nearly as abhorrent.
August 23, 2008
On 2008-08-23 00:28:19 +0200, Sean Kelly <sean@invisibleduck.org> said:

> Fawzi Mohamed wrote:
>> On 2008-08-22 22:10:21 +0200, Leandro Lucarella <llucax@gmail.com> said:
>> 
>>> Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
>>>> Leandro Lucarella wrote:
>>>>> Don, el 18 de agosto a las 12:41 me escribiste:
>>>>>> I cannot understand the rationale for a toString() member function which
>>>>>> doesn't support formatting.
>>>>> I think is useful only for debugging purposes.
>>>>>> C++ got around this by giving state to the iostream classes.
>>>>> I think C++ formatting is heavily ill. All the manipulator stuff is
>>>>> madness.
>>>> 
>>>> It's horrific but surprisingly flexible.  I've created stateful formatters for
>>>> various protocols and made it work all invisibly with the formatting hooks
>>>> provided in C++.  For example:
>>>> 
>>>> std::cout << a << b << c << std::flush;
>> 
>> I think that putting formatting details in the stream is a very good idea for serialization, but not for normal textual output, the two things are not the same (even if it might be useful to use some xml serialization for some objects, and send it together with "normal" text).
> 
> Yeah, the above example was a simplified version of some pretty fancy stuff I did for a multi-protocol server app.  It made serialization painfully easy for the user (so long as the proper support code was built into the formatting frastructure), but was really operating well beyond the scope of what iostream formatting was intended to do.
> 
> In general though I think it's preferable to have such things done differently than raw IO.  Tango has some support for this with its Reader/Writer model in tango.io.protocol, but even that is somewhat limited to specific categories of protocols.  For example, I recently tried using it for ASN.1 transcoding and it just isn't sufficient.

Yes I think that it is the correct approach to have special streams for serialization, as long as they can then be hooked to the "normal" streams then everything is ok.

It is a pity that Reader/Writer are not sufficient, could it be extended to support it, or a different approach is needed?
Actually my needs are smaller, I would love to have at least a textual streaming protocol (xml based?) that works with Reader/Writer for quick dump/read of my objects..

Fawzi

August 24, 2008
Leandro Lucarella wrote:
> Don, el 18 de agosto a las 12:41 me escribiste:
>> I cannot understand the rationale for a toString() member function which doesn't support formatting.
> 
> I think is useful only for debugging purposes.

I agree. Which means that having I/O functions call toString() is a broken design (I'm looking at you, writefln!)

> 
>> C++ got around this by giving state to the iostream classes.
> 
> I think C++ formatting is heavily ill. All the manipulator stuff is
> madness.
> 
August 24, 2008
Don a écrit :
> Leandro Lucarella wrote:
>> Don, el 18 de agosto a las 12:41 me escribiste:
>>> I cannot understand the rationale for a toString() member function which doesn't support formatting.
>>
>> I think is useful only for debugging purposes.
> 
> I agree. Which means that having I/O functions call toString() is a broken design (I'm looking at you, writefln!)

But... writefln is used a lot for debugging purposes. If you quickly want to print something to the console, it's much faster not having to use toString() everywhere.
1 2 3
Next ›   Last »