more naming

Adam D. Ruppe destructionator at gmail.com
Sat Jan 22 09:57:38 PST 2011


Torarin wrote:
> It sounds like the current replace should be named replaceAll.

That would break lots of existing code, and it doesn't seem to
fit.

If replacing only the first element means it can take a special
range, whereas all other n is is the same, it seems obvious
that replaceFirst be the special function (that's what I'd call
it too) and normal replace be either:

a) Kept exactly as it is

b) Add a runtime parameter:

string replace(string item, string replaceWhat, string replaceWith, int howMany =
int.max);

So it stays the same as it is now by default, but can cover
any number of items in the same way.



If n == infinity was a special case for algorithm or input,
it'd make sense to give it a special name (though still big
points against it because of inertia). But it isn't. n==1 is
special, but n != 1 is always the same.

So I'd say go replaceFirst.


More information about the Digitalmars-d mailing list