3 ms·
On the other hand, we have to teach people about aliasing vs cloning in imperative languages. a = [1, 2, 3] b = a b.append(4) assert a == [1,2,
by rovolo 7y ago
On the other hand, we have to teach people about aliasing vs cloning in imperative languages.
a = [1, 2, 3]
b = a
b.append(4)
assert a == [1,2,3]
No matter which paradigm we use, there are going to be hidden traps new programmers need to learn. I think there might be fewer roadblocks in an immutable language because you can examine each function in isolation. There's a smaller chance a beginner will screw something up on line 10 which causes a problem on line 150. More moving parts makes it easier to get stuck on a buggy program.
On the other-other hand, it is a slower ramp up to doing useful things. It's much easier to read/write to files and draw graphics in an imperative language.
- kazinator 7y agoAliasing versus cloning can bite you even if nothing in the program is imperative. For instance, somewhere in the program you choose the wrong one among the available set of equality functions (all of them beautifully pure). If the immutable language has a single equality operator which makes it impossible to tell whether or not a value has been cloned, you might be safe from this issue.
- rovolo 7y agoThere shouldn't be a difference between Aliasing and cloning for immutable data because you can't change the data. Deep vs shallow operations is an issue in both imperative and functional programming. In python, you have '==' vs 'is' for different types of equal. You have deep vs shallow copy: https://docs.python.org/3/library/copy.html https://docs.python.org/3/library/copy.html