4 ms·
Aside from the fact that they carried that style of naming over from Objective-C, the one benefit I see is that it makes it obvious that it returns the result i
by alexbock 11y ago
Aside from the fact that they carried that style of naming over from Objective-C, the one benefit I see is that it makes it obvious that it returns the result in a new string rather than modifying the object itself. In C++ you would need to look at the signature to tell which way a method named replace worked, e.g.
void A::replace(const A& source, const A& dest);
vs
A A::replace(const A& source, const A& dest) const;
That said, I think you can get this same benefit without such a verbose name. Perhaps something like "withReplacement"?
- cballard 11y agoA solution to this would be to disallow mutable value types. Then, all methods would _have_ to return a new instance. The compiler implementation could use mutability behind the scenes for efficiency, while the language exclusively allowed immutable values.