V2 string
Vladimir Panteleev
thecybershadow at gmail.com
Wed Jul 4 18:44:41 PDT 2007
On Thu, 05 Jul 2007 02:23:11 +0300, Derek Parnell <derek at psych.ward> wrote:
> This leads to constructs like ...
>
> char[] result;
>
> result = SomeTextFunc(data).dup;
Is SomeTextFunc allocating a copy of the string which it is returning? If it is, then there's no reason why it should return a "string" type. If it isn't, then modifying the data in the returned char[] could have unforeseen consequences.
> Another commonly used idiom that I had to stop using was ...
>
> char[] text;
> text = getvalue();
> if (wrongvalue(text))
> text = ""; // Reset to an empty string
Since empty string literals don't really point to data, I'd suggest that empty string and array literals shouldn't be const/invariant in favor of the above example. It breaks some consistency, but "a foolish consistency is the hobgoblin of little minds" ;)
--
Best regards,
Vladimir mailto:thecybershadow at gmail.com
More information about the Digitalmars-d
mailing list