Live data from Hacker News

Why general inheritance is flawed and how to finally fix it

minborgsjavapot.blogspot.com

101–104 of 104 posts

Re: Why general inheritance is flawed and how to finally fix it

#101
post #40
post #34

https://lwn.net/Articles/548560/ I really enjoyed the article above, which I read many years ago (before Rust 1.0!) which discusses how Golang and Rust handle polymorphism and code-reuse without classic object inheritance. My current thinking is that software objects are a general-purpose tool, but classic object inheritance should rarely be used as it is a solution to a narrow problem—classes should be "final" by de…

I mostly agree, but there's one place where it does make a lot of sense to keep the hierarchy open: exceptions. Ability raise a specific error and catch it in a generic handler is very useful.

Agreed. Exceptions tend to trivially respect the Liskov substitution principle and generally hold little state besides a debugging string. It's when you subclass an object as a method of code reuse that you start running into problems.

Re: Why general inheritance is flawed and how to finally fix it

#102

I think that composition is absolutely better than inheritance except for one thing: boilerplate. The issue is that boilerplate is kind of important. You don't want to litter your code with "f150.ford.car.vehicle.object.move(50, 50)". You can and should re-implement "move" so that you only have to call "f150.move(50, 50)", but that still requires boilerplate, just in the "F150" class. Often you have class containing…

Check out Scala 3's 'export' feature.

https://docs.scala-lang.org/scala3/reference/other-new-featu...

Re: Why general inheritance is flawed and how to finally fix it

#103
post #42

Earlier quoted context omitted.

COM solves this with delegation, where objects can only implement the methods that they care about and delegate everything else to the aggregated type, which provided the full interface. However, depending on which stack one is using (VB 6, .NET, MFC, ATL, WRL, WinRT), the amount of boilerplate to deal with the runtime differs.

I wish more languages (in fact, any popular languages!) had convenient syntax for this.

Any time one dares to defend Pascal's "with" statement, a shitstorm starts...

Re: Why general inheritance is flawed and how to finally fix it

#104
post #89

The real world rarely sticks with nice hierarchies. Variations of set theory is more powerful, but would generally require merging RDBMS with IDE's, which does deserve more R&D. Using code to manage complex sets is limiting; query languages do it smoother because that's what they were intended for. I've experimented myself with "table oriented programming", but don't have time to explore all the leads I uncover and r…

> I've experimented myself with "table oriented programming"

Is that you, Bryce?

Post reply on HN