D1 -> D2
Walter Bright
newshound2 at digitalmars.com
Thu Nov 18 11:50:06 PST 2010
Steven Schveighoffer wrote:
> On Thu, 18 Nov 2010 14:19:12 -0500, Walter Bright
> <newshound2 at digitalmars.com> wrote:
>
>> Steven Schveighoffer wrote:
>>> My recommendation -- when you are ready, switch wholly to D2. Don't
>>> bother with compatibility, it's just not possible.
>>
>> From what you wrote, it appears that most of the difficulties were in
>> dealing with strings. Might I suggest:
>>
>> 1. Replace all occurrences of char[] with string.
>>
>> 2. Compile to find every place that mutable strings are used.
>>
>> 3. Refactor the code to clearly encapsulate where mutable strings are
>> created and manipulated, and as the last step, cast them to string.
>
> But string is not always what is desired. It depends on the library.
Right.
> Tango uses mutable arrays everywhere because it prefers not to use the
> heap as much as possible. For example, something might take a char[]
> buffer, and a function may pass in a stack-allocated array for the
> buffer. Changing this to string is useless.
That's where refactoring comes in. I haven't looked at the Tango code, but
there's a big difference between "using mutable arrays everywhere" and actually
needing to mutate them. Only the latter needs to be char[], and the boundaries
between the two are bridged with a .idup or a cast(string).
If Tango is relying on string literals to be char[], i.e. be mutable, this is a
serious bug and will cause seg faults. So, this issue must have already been
dealt with in Tango, and codifying string literal types as "string" rather than
"char[]" should not negatively impact it.
And lastly, if there are APIs in tango that accept char[] and leave the caller
perplexed about whether the API will mutate the string or not, that is something
that using string for the non-mutating ones nicely resolves.
More information about the Digitalmars-d
mailing list