raincole 39 minutes ago

In other words, immutable != read only.

In C# ReadOnlyCollection<T> and ImmutableArray<T> are two completely different things for this exact reason.

comrade1234 an hour ago

Isn't NSMutableArray a subclass of NSArray in a few languages?

  • bartvk 23 minutes ago

    Good one, yes. It was like that in Objective-C, and in the early versions of Swift. I know you know this, but it's useful to summarize for myself:

    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).

  • catoc an hour ago

    Yes, that’s ObjC, any NSMutableArray is an NSArray (and an NSObject) - classes passed by reference.

    Swift is completely different. Standard arrays are structures, always mutable - value types passed by value

zkmon 42 minutes ago

The fact that it requires so much explanation, indicates the level of degradation in the reasoning ability of the audience. A value of a subtype shall deliver all of the expectations of its super type, because it is wearing both the hats of super type and sub type.

  • Shorel 26 minutes ago

    Not all all. It merely indicates that this is an strict logic approach to the topic.

    https://commonplacefacts.com/2022/07/27/principia-mathematic...

    • applfanboysbgon 15 minutes ago

      What part of GP's one-sentence explanation is not strictly logical? Does obfuscating a simple logical concept by describing it in academia-wanky-terms like Liskov's Substitution Principle make it More Logical? Or does it just make the author and their in-crowd feel more intelligent?

      • pestatije 11 minutes ago

        intelligence is overrated

gus_massa 13 hours ago

Yep, I wondered that for a few optimizations in Racket. It's harder than it looks, probably something about covariant or contravariant types, I gave up.