On Tue, 09 Mar 2010 12:33:01 -0500, Andrei Alexandrescu
<[email protected]> wrote:
In wake of printing multi-dimensional arrays, I agree that start and end
delimiters should be present by default. If delimiters are present, it
only makes sense to make the array look like a D array, so the ", "
becomes an acceptable proposition.
That's great!
I'm unsure about strings - should "to" go all gung-ho on quoting and
escaping quotes etc.? That's a bit odd. Consider:
auto str = to!string("hello world");
I'd expect the call to be an identity application that makes str equal
to "hello world". So far so good. Then say I convert with "to" an array
of strings to a string:
auto str2 = to!string(["hello world"]);
Now str2 is "\"hello world\"", i.e. has an extra pair of quotes.
I think you mean "[\"hello world\"]"
So "to" applied to an array does not always use "to" applied to each
element of the array - it has a completely different behavior. I wonder
whether that's a desirable behavior.
I would say no. I guess you could make the argument that strings are
already arrays treated specially, but I don't think it adds much to put
the quotes there. Plus, it allows simpler code and documentation, you can
define the conversion of an array as a purely recursive function, even if
it may not be implemented that way.
Note that ranges should convert identically to arrays, making arrays
special would make things odd.
Another thing that's unclear to me is whether writeln and "to" should be
defined such that
write(to!string(stuff))
and
writeln(stuff)
produce the same text. Currently that's the general plan, but I wonder
whether we should change the approach.
I like that, it shows consistency. If you want to change the format, you
can via to's parameters. But the most useful defaults should be the same
in writeln.
Even though to is a way to get a crude serialization function, I don't
know if it will be sufficient or efficient for a serious serialization
library (i.e. I don't think it's worth making 'to' that smart). But it is
sufficient as a debug tool, it just needs better defaults.
-Steve