|
|
|
|
|
by Silhouette
2555 days ago
|
|
I think part of the problem is that many popular languages now default to using two very different behaviours for elementary tasks like passing variables or parameters around, depending on whether the variable is a "reference type" or a "value type". Simple things like numbers have value semantics. Objects and whatever else works a bit like an object in your language have reference semantics. If you want a reference to a simple value like a number, you box it so the basic type is now wrapped in an object, or something equivalent. Maybe that's even a semi-automatic process that is done for you in some cases. Anyway, that's just how variables work, and the idea that in principle you could have a value of any data type or a reference to any data type doesn't even occur to someone who has learned this way. Then you get to data structures, and you're trying to explain the fundamental difference between dense, buffer/array-like structures and sparse, graph/pointer-like structures, and there might be no concept of an underlying memory model where the difference is clear. This has always seemed like a horribly ambiguous and inconsistent mental model to me, and there must surely have been quite a few bugs caused by programmers not clearly understanding the differences between value and reference semantics and exactly when each applies in their chosen language(s). And yet for reasons I can't understand, many of the popular languages today do seem to follow something close to this model. |
|
My favourite book at college about (the real) data structures started building the array, even if it was already implemented in the language.