Why isn't mutable a subtype of immutable, or vice versa?
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
Why isn't mutable a subtype of immutable, or vice versa?
Unofficial Hacker News client; not affiliated with Y Combinator.
comrade1234 · · focus · HN ↗
bartvk · · focus · HN ↗
Basically inheritance is the wrong tool for this kind of stuff. NSMutableArray inherits from NSArray, so it can be passed to anywhere NSArray is expected (upcasting).
So you design your classes and expect them to be immutable, but you can't use NSArray anywhere. Because otherwise, it'll be mutable after all. You can do a runtime check as a workaround.
(I truly believe OOP should only be taught in computer science as a relic).
brabel · · focus · HN ↗
renox · · focus · HN ↗
The problem is the "exclusive access to it", most language aren't Rust.. Some Ada-implementation has the problem ( <a href="https://news.ycombinator.com/item?id=43001394">https://news.ycombinator.com/item?id=43001394 )