V2 string

Regan Heath regan at netmail.co.nz
Thu Jul 5 01:30:54 PDT 2007


Walter Bright Wrote:
> 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;

Aaargh!  You're confusing empty and non-existant (null) again!  <g>

In some cases there is an important difference between the two.  In this case maybe not I don't really know.

Regan




More information about the Digitalmars-d mailing list