News for hackers. Stuff that matters.
Re:JavaScript Array.push is 945x faster than Array.concat by twic on Thursday May 23, 2019 @11:37AM (#19992715)
> Am I doing things wrong?

No. Mutating state that is shared between different parts of a program is often a bad idea. The functional programming community learned the first half of that, and now goes round preaching the mistaken idea that all mutation is bad.

Re:JavaScript Array.push is 945x faster than Array.concat by seanmcdirmid on Thursday May 23, 2019 @11:54AM (#19992857)
Not everyone, or even most of the FP community does that. There is even a famous paper on how lambda is the ultimate imperative.
Re:JavaScript Array.push is 945x faster than Array.concat by Scarbutt on Thursday May 23, 2019 @12:17PM (#19993060)
Is useful in single threaded programs too, an example is to avoid having to do deep copies everywhere (which is less performant than using persistent data structures) as to have multiple versions in time of some data that you can hang on to.
Re:JavaScript Array.push is 945x faster than Array.concat by staticassertion on Thursday May 23, 2019 @01:31PM (#19993866)
I don't think they're referring to multiple threads when they say different part of the program, but instead that you should be able to reason about mutation locally.

For example, if I pass an argument into a function, it may be 'unexpected' that the argument is mutated - I can not reason about that mutation locally (unless it's very explicit or a known idiom such as push).

However, within a function, avoiding mutation seems pointless as you should have no trouble reasoning about it. At some point you really are just throwing away performance with significantly diminishing benefits.

Shared mutability across threads is definitely a huge pain in the ass though.

In the end I think we're all just trying to reduce the state space we have to manage in our heads when we read and write code, and removing mutability reduces that space.

Re:JavaScript Array.push is 945x faster than Array.concat by Scarbutt on Thursday May 23, 2019 @02:13PM (#19994337)
However, within a function, avoiding mutation seems pointless as you should have no trouble reasoning about it. At some point you really are just throwing away performance with significantly diminishing benefits

Ok, but here you are doing all the manual work of creating a copy as to avoid mutating the arg/returning a new one and, it may be less peformant because of whole copy, knowing your programming language automtically defaults and does this for you in a performant way is a big win for reducing cognitive overhead in large programs.

Re:JavaScript Array.push is 945x faster than Array.concat by pdimitar on Saturday May 25, 2019 @07:19AM (#20008349)
I don't disagree, but the way Erlang (and thus Elixir) does it is that you get a small stack space to contain your immutable data -- and when you unwind the function the stack just gets thrown away instead of involving the GC which I'd argue is still plenty fast.

I do agree that copying stuff around is generally expensive. I am just unsure how expensive it is in smaller functions that aren't called 10_000 times a second.