8 comments

  • js815 minutes ago
    I feel like the explanation is overcomplicated. Types are properties of values, not variables. Mutability is a property of variable, not of a value.<p>So it&#x27;s kind of a categorical error. (I want to joke here that all categorical errors are just type errors in category theory.) When we speak of &quot;type of a variable&quot;, we mean this variable can only be assigned (bound to) values of certain type. This has nothing to do with whether it can be reassigned (i.e. mutability).<p>So you don&#x27;t even need the notion of subtyping to explain this.<p>Also, one could probably define variable as a monad over its type.
  • Mikhail_Edoshin6 minutes ago
    So the problem is that the semantic of methods (car, cdr) is not well defined: it is either &quot;give me that member&quot; or &quot;give me that member and guarantee next time the result will be same&quot;. And the solution is to clearly separate those by adding more method names.
  • BlackFly46 minutes ago
    If you pair mutability with exclusive access then you have handled the objection raised by the (some may say overly) strict definition of subtyping here and also the attempt to argue over the objection. No code which asks for an immutable instance will ever observe the mutability because the ask for an immutable reference is exclusive. Therefore, you could pass the mutable reference but so long as something holds onto that reference the mutability is no longer available to other code.<p>So mutability xor aliasing provides this strict subtyping relation. Of course, you also then need ways of loosening this by providing objects without such a contract and you enter the land of interior mutability, where again the mutable methods can be understood as a part of a subtype because a holder of the reference without mutable methods was explicitly told that there was no the guarantee that the object wouldn&#x27;t change.
  • raincole1 hour ago
    In other words, immutable != read only.<p>In C# ReadOnlyCollection&lt;T&gt; and ImmutableArray&lt;T&gt; are two completely different things for this exact reason.
  • cubefox21 minutes ago
    I would phrase it in terms of subsets. All cats are mammals, therefore &quot;cat&quot; is a subtype of &quot;mammal&quot;. So the possible values of the type &quot;cat&quot; are a subset of the possible values of the type &quot;mammal&quot;.<p>In contrast, neither are the mutable things a subset of the immutable things nor the other way round. It&#x27;s not the case that everything mutable is immutable nor that everything immutable is mutable. The two types are disjoint.
  • comrade12342 hours ago
    Isn&#x27;t NSMutableArray a subclass of NSArray in a few languages?
    • bartvk1 hour 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&#x27;s useful to summarize for myself:<p>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).<p>So you design your classes and expect them to be immutable, but you can&#x27;t use NSArray anywhere. Because otherwise, it&#x27;ll be mutable after all. You can do a runtime check as a workaround.<p>(I truly believe OOP should only be taught in computer science as a relic).
      • nicky044 minutes ago
        &quot;Was&quot; like that? .... Some of us still use Objective-C!
    • catoc1 hour ago
      Yes, that’s ObjC, any NSMutableArray is an NSArray (and an NSObject) - classes passed by reference.<p>Swift is completely different. Standard arrays are structures, always mutable - value types passed by value
  • gus_massa13 hours ago
    Yep, I wondered that for a few optimizations in Racket. It&#x27;s harder than it looks, probably something about covariant or contravariant types, I gave up.
  • zkmon1 hour 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.
    • Shorel1 hour ago
      Not all all. It merely indicates that this is an strict logic approach to the topic.<p><a href="https:&#x2F;&#x2F;commonplacefacts.com&#x2F;2022&#x2F;07&#x2F;27&#x2F;principia-mathematica-300-page-proof-one-plus-one-equals-two&#x2F;" rel="nofollow">https:&#x2F;&#x2F;commonplacefacts.com&#x2F;2022&#x2F;07&#x2F;27&#x2F;principia-mathematic...</a>
      • zkmon2 minutes ago
        If the article is written for human consumption, then it fails the primary goal (or logic?) of being useful. If a human has to digest a flood of this logic slop just to get convinced about this simple concept, they are not going to be able to do anything useful.
      • applfanboysbgon1 hour ago
        What part of GP&#x27;s one-sentence explanation is not strictly logical? Does obfuscating a simple logical concept by describing it in academia-wanky-terms like Liskov&#x27;s Substitution Principle make it More Logical? Or does it just make the author and their in-crowd feel more intelligent?<p>Note, also, that the article isn&#x27;t even objective. It asserts that the definition of a subtype <i>is</i> Liskov&#x27;s principle. However, Liskov&#x27;s principle is only one of multiple possible definitions. In other words, the article is really only invoking Liskov&#x27;s name as an appeal to authority. So much for strict logic.
        • pestatije58 minutes ago
          intelligence is overrated