Personally, I'm undecided. Part of me would prefer the explicit naming difference (less chance for bugs), however the idea of using the type system to infer the kind of operation wanted is nice. What do you all think?
the idea of using the type system to infer the kind of operation wanted is nice
I disagree, var x = ...; toUpper(x) shouldn't be different from let x = ...; toUpper(x) or from toUpper("abc").
Also I don't know why we need to decide anything here, some things are more naturally in-place string ops (chomp, del), others (strip, toUpper, replace) naturally return a new string result. Being 100% consistent is simply unnatural and does not lead to significant benefits. (Try to implement replaceInPlace as an exercise...)
More useful for performance is not "in place", but "pass buffer to add the result to by var":
result = "$1($2, $3) Error: $4" % [
my.filename, $getLine(my), $getColumn(my), errorMessages[my.err]]
Can then via a TR macro be optimized into:
result = ""
result.add my.filename
result.add "("
result.addInt getLine(my)
result.add ", "
result.addInt getColumn(my)
result.add ") Error: "
result.add errorMessages[my.err]
Please, let's not fragment the conversation.
@Araq: Can you reply to my questions in the Github issue?
Please, let's not fragment the conversation
What does that mean? Is the github discussion meant to be moved to the forum? Or are we meant to answer on github then?
You mention making a macro to make chaining easier. I recently wrote a basic one, might help with imagination.
@araq The problem with that philosophy is that people have different ideas of what procedures should naturally return a copy vs an in-place modification.
I've looked at the boost c++ libraries, and all the procedures there are in-place by default, with a "_copy" suffix for copying procedures.
@araq Well, it is an option worth considering. Alternately, we could take the opposite stance from boost and make everything copy by default (since that's what's done anyway).
In the end, I want to be able to do something like getInput().strip().toLower() without creating 2-3 string copies. After all, what's the point of having mutable strings if you can't save memory when using them?