this post was submitted on 01 Jan 2026
12 points (92.9% liked)

Programming

24318 readers
260 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] squaresinger@lemmy.world 7 points 1 week ago

The one good principle. And I now I can see why: it was invented by people who knew their maths — type theory in this case. In lay terms it’s simple: anything you can observe about the base class, remains true of its derived classes. That way you can pretend instances of the derived classes are also instances of the base class, without any nasty surprise.

On the one hand, duh: that’s just subtyping. But on the other hand, very few type systems enforce it — Java and C++ do not. That makes it very easy to make a dumb mistake like overriding a stable sort() method, and make it not stable for the derived class.

Javas immutable lists are an example of that right in the standard library.

The super type List has mutability. When you call any of these methods in the immutable list, you get an exception.

So if you have an arbitrary List object, you have no idea whether calling any method that mutates the object will work or not.

And this is doubly bad with the linter demanding you use Stream.toList() (which returns an immutable list) instead of Stream.collect(Collectors.toList()) (which returns a mutable list).

Horrible, dumb design.