xxxInPlace or xxxCopy?

bearophile bearophileHUGS at lycos.com
Wed Jan 19 15:47:07 PST 2011


Andrei:

> One question is whether operations should be performed in place or on a 
> copy. For example:

Strings are meant to be immutable, and the functional style is simpler to understand and safer to use, so I firmly suggest the default (with shorter names) functions to create a new string/array, and the versions that work in place with a longer name.

In some languages the versions that work in-place have a bang (!) suffix, like replace and replace!. I guess a name like "replaceBang" is too much cryptic.


> auto s1 = replace(s, "lil", "li'l");
> assert(s == "Mary has a lil lamb.");

You probably meant:
> assert(s1 == "Mary has a lil lamb.");

Bye,
bearophile


More information about the Digitalmars-d mailing list