News for hackers. Stuff that matters.
Re:Why Is Swift's String API So Hard? by alexbock on Friday November 06, 2015 @11:41AM (#10520352)
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"?

Re:Why Is Swift's String API So Hard? by cballard on Friday November 06, 2015 @11:45AM (#10520376)
A 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.