auto newStr = replace(str, "hello", "world");
replaceInPlace(newStr, "world", "hello");
it's quite clear that the first one returns a value and the the second
one does
it in place. Whereas if you have
auto newStr = replaceCopy(str, "hello", "world");
replace(newStr, "world", "hello");
the first one is clear, but the second one is only clear because seeing
the first
one makes it obvious that the second one must be doing something
different.
I don't understand how the first two are clear and the last two are not so.
Where both have the name "replace" for different things, and replace to me
means "replace in place".
With this in hand, how is the first "replace" is quite clear?
I am sure this is the case for many people. Problem is the naming here.
If you have named it something like "replaced" and return a copy, it would
be obvious and clear.
Here, aren't you just dictating functional language rules to a
multi-paradigm language, implicitly?
In a fully functional language "replace(something)" might mean "replace
and give me a copy", but it is not what we have.