V2 string

Walter Bright newshound1 at digitalmars.com
Thu Jul 5 00:42:25 PDT 2007


Derek Parnell wrote:
> The idiom I'm using is that functions that receive text have those
> parameters as 'string' to guard against the function inadvertantly
> modifying that which is passed, and functions that return text return
> 'string' to guard against calling functions inadvertantly modifying data
> that they did not create (own).
> 
> This leads to constructs like ...
> 
>    char[] result;
> 
>    result = SomeTextFunc(data).dup;

If you're needing to guard against inadvertent modification, that's just 
what const strings are for. I'm not understanding the issue here.

> Another commonly used idiom that I had to stop using was ...
> 
>    char[] text;
>    text = getvalue();
>    if (wrongvalue(text))
>        text = ""; // Reset to an empty string
> 
> I now code ...
> 
>        text.length = 0; // Reset to an empty string
> 
> which is slightly less readable.

This should do it nicely:

	text = null;



More information about the Digitalmars-d mailing list