4 ms·
Sorting is an example, quicksort is fast since it is done in place and mutates the data instead of allocating new memory. Very few algorithms are not faster wi
by username90 5y ago
Sorting is an example, quicksort is fast since it is done in place and mutates the data instead of allocating new memory.
Very few algorithms are not faster with mutable variables.
- benrbray 5y agoAs I understand it, immutability usually refers to mutable data structures hidden behind an interface that allows the programmer to reason about things as if they were immutable. The naive implementation is of course to duplicate all data whenever a change is made, but pure / immutable languages use smarter things like persistent data structures behind the scenes. If the compiler knows the original data is never needed, it can optimize away the old copies, too. At least that's the hope, I'm not sure how true it is.
- username90 5y ago> As I understand it, immutability usually refers to mutable data structures hidden behind an interface that allows the programmer to reason about things as if they were immutable. That is the definition of an algorithm, not immutability.