logoalt Hacker News

rramadass01/22/20251 replyview on HN

> No one should ever use inheritance in any long-term production use case without some way of enforcing strict discipline, ensuring that calls can only go one way -- up or down, but not both. I don't know to what extent tooling to enforce this discipline exists.

Disagree with your first part. Inheritance used to express Subtyping is different from that used for Code-reuse and yet again different from that used for implementing Framework skeleton structure. You have to disambiguate them carefully when using it. See the article linked to by user "Fannon" here - https://news.ycombinator.com/item?id=42789466

As for tooling, you have to enforce the contract using pre/post/inv clauses following Meyer's DbC and also explicit documentation.


Replies

sunshowers01/22/2025

Thanks for that article -- I have to agree with Jacob Zimmerman in the comments to the article:

> I don’t get it. I read one part of the article, think I get it, then I read a different part and what I read there doesn’t jive with what I thought I understood. And I can’t figure out how to reconcile them.

---

> As for tooling, you have to enforce the contract using pre/post/inv clauses following Meyer's DbC and also explicit documentation.

I think we call them asserts and type-level state machines :)

I don't really believe in documentation as enough of a barrier to doing worse things. It must, at a structural level, be easier to do better things.

show 1 reply