News for hackers. Stuff that matters.
Re:Copying data is wasteful, mutating data is dangerous by cestith on Thursday January 09, 2020 @04:35PM (#22006079)
This is consistent with Ruby. It often includes both in the core. There's .gsub() and .gsub!() for text substitution in the String class, for example, or .select() and .select!() for the Hash class.
Re:Copying data is wasteful, mutating data is dangerous by kwertzzz on Thursday January 09, 2020 @05:01PM (#22006370)
This is interesting to know, because Julia uses exactly the same approach[1] (now I know where it comes from). To me it seems to be the ideal solution: use the in-place normalize!(X) where performance is important, otherwise use the more convenient allocating variant normalize(X). The exclamation mark makes it clear that the array is modified.

[1] https://docs.julialang.org/en/v1/base/collections/#Base.sum!

Re:Copying data is wasteful, mutating data is dangerous by fasquoika on Thursday January 09, 2020 @05:15PM (#22006480)
>(now I know where it comes from)

Both Julia and Ruby got this from Scheme and it might be even older than that.

Re:Copying data is wasteful, mutating data is dangerous by anamexis on Thursday January 09, 2020 @05:22PM (#22006545)
Unfortunately it isn't completely consistent, for example Array#delete and String#concat
Re:Copying data is wasteful, mutating data is dangerous by cestith on Friday January 10, 2020 @12:08PM (#22012478)
Well, yes. Julia here is consistent with something in Ruby. In my experience it's one of the three major complaints about Ruby is how inconsistent it can be within itself.

The other two major ones are the number of core ways to the the same thing and the slowness of the interpreter. The first is a matter of taste. The second is a technical issue with the interpreter mostly independent of the language and/or a question of fitness for specific projects.