V2 string
Derek Parnell
derek at psych.ward
Thu Jul 5 15:31:22 PDT 2007
On Thu, 05 Jul 2007 11:51:30 -0700, Walter Bright wrote:
> 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.
Thanks. This is what I meant by taking rethinking the design of my
routines. I'll strongly consider your suggestion even though it does
complicate the algorirhm for readers of the code.
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
More information about the Digitalmars-d
mailing list