V2 string

Walter Bright newshound1 at digitalmars.com
Thu Jul 5 11:51:30 PDT 2007


Derek Parnell wrote:
> I'll make my code example more free from assumed functionality.
> 
> 
>  char[] qwerty;
>  
>  qwerty = KJHGF(poiuy).dup;
>  version(xyzzy)
>  {
>      MNBVC(qwerty);
>  }
> 
> As you can see, my point is made without regard to converting stuff to
> lower case.

My point is that the way the snippet is written is inside out. Do not 
use .dup to preemptively make a copy in case it gets changed somewhere 
later one. The style is to make a .dup *only if* the contents will be 
changed and do the .dup *at the site* of the modification.

In other words, dups should be done from the bottom up, not from the top 
down.

I think such a style helps fit things together nicely and avoids strange 
.dups appearing in inexplicable places.



More information about the Digitalmars-d mailing list