the second returns a new list with doubled contents. The first modifies the list in place.
in functional programming, your sort function would return a new sorted list
The old list still exists
I have never understood why this is a good thing. Why would you want to keep the unsorted list around unless you needed to use it later? It's a waste of memory and time.
>>35
To me, this thread only reaffirms my belief that functional programming languages and their users have absolutely no understanding of the practical issues of programming in the real world; they believe memory and memory bandwidth is infinite, and so is computation speed.
I have read SICP and studied FP. It's
interesting that computations can be modeled without state and the lambda calculus etc., but it's all just mental masturbation. Real computers, and indeed, the Universe as we know it, is stateful (
as we know it - because some interpretations of QM assert that new copies are made every time something changes, but regardless, it's state from our point of view.) It's all as theoretical and impractical as T
ouring machines.
I have seen many beginning programmers write code that makes lots more copies of data than necessary (especially objects, which have more overhead due to constructors etc.), so immutability may be "easier" to think about in some ways, but once you learn how a computer
really works (and that
should have been the first thing you learned), it's trivial to see how much more efficient it is to not make new copies unless they're actually needed.
>>37
for(int i=0;i<l;i++)
a[i] *= 5;