by duncanawoods · 8y ago · 0 comments
I think you have let functional programming and immutable data-structures bias your world view.
The real world is mutable and the wonder of the digital mutable world is that it is pretty much just will-alone that can set attributes as you describe. It is immutability that is a trendy but artificial layer on top of this reality.
Only if you ignore time. It's not possible to change the state of the world at some previous instant (as far as our understanding of physics is concerned). The mutable world model is an artificial construction that aligns with our human perception.
(Streams in this case not being streams in an I/O sense, just an example of a class).
One alternative would be to keep track of two types for an array: the most general type that can be stored into it and the most general type that might come back out of it. Any type cast that makes the types storable more strict or the type expected coming out less strict should be allowed. If you throw in a bottom type in your type system, then you get immutable arrays for free.
Of course, such a type system would probably cause a revolt among the majority of Java programmers for being too complex.
EDIT: Good reference: https://www.atlassian.com/blog/software-teams/covariance-and...
As usual the truth is somewhere in the middle, which is why I don’t like the periodically recurring discussions why OO is bad, FP is good or vice versa. I think the article splits up the issue quite nicely, the conclusion I get from it is that the answer to the question whether to use inheritance or not is ‘it depends’.
I talked more about this in this MeetingC++'17 talk: https://www.youtube.com/watch?v=NMol_5-2owo
Depends on your definition on vehicle. For many purposes (e.g. going somewhere) it could be, especially if it also existed.
Subtyping just means "having a taxonomy of things, where we can substitute things lower on the taxonomy -- more concrete, more specialized and so on" with things higher up when wanting less abstraction (and vise versa).
And this is pretty much the case with the world -- Plato's "ideas", scientific taxonomies (e.g. of animals and plants), or RDF and semantic taxonomies, and so on are all based on the same concept.
(That doesn't mean they're perfect descriptions of the world, like our class taxonomies in OOP don't lead to perfect descriptions of most problem domains either).
>What about a vehicle which doesn't have wheels, in a world built around assuming that vehicles have wheels?
That's a problem of definition of what should belong in the class of things we call "vehicle" (and you could have the exact same questions when doing OOP).
As such it's not an argument in whether the real world has or doesn't have subtyping.
The real world has both values and objects, any ideology that doesn’t acknowledge both is just fooling itself.