Live data from Hacker News

Inheritance Often Doesn't Make Sense

sicpers.info

191–200 of 255 posts

Re: Inheritance Often Doesn't Make Sense

#191
post #135

Earlier quoted context omitted.

The carpenter has certainly altered the dimensions of the board , but in so doing has he not destroyed the old rectangle and created a new one?

No. Even less so with the pastry dough squashed into new dimensions. Or when a citizen turns into a soldier -- an army camp is like a soldier factory/constructor. Hmm, how's that for a mixed metaphor?

I disagree. If you remold a square piece of pastry dough into a circle you haven't "circled the square", you have destroyed the square entirely!

I don't quite get the army metaphor, but I don't think the relationship of "citizen" and "soldier" is analogous to that of "rectangle" and "square" or even "rectangle" and "rectangle with different dimensions".

Re: Inheritance Often Doesn't Make Sense

#192
post #112
post #96

Earlier quoted context omitted.

> The conceptual purist perspective: > > The notion of object oriented programming is completely misunderstood. It's not about objects and classes, it's all about messages. - Alan Kay > Given that Alan Kay is the one who came up with the term "object oriented", it might be wise to give him authority about the definition.

That would be next to impossible, since the term is overwhelmingly used by working programmers in the context of C++/Java/C#/etc. Also, I suspect that the only reason Kay's version is even brought up in every discussion of the term is some sort of programmer-hipster signaling thing. Not that Kay's OO isn't important - it is. It's just hardly ever relevant to the actual discussion.

> Not that Kay's OO isn't important - it is. It's just hardly ever relevant to the actual discussion.

Having a debate over inheritance without a consensual definition of OO is gonna lead us nowhere.

The word "OO" has been a selling buzzword for several decades. Which means our best bet in getting a sensible definition is to pick the original one.

This is why we keep bringing up "Kay's OO" (which also is, by the way, Coplien's OO, Reenskaugh's, Dave West's ...)

Re: Inheritance Often Doesn't Make Sense

#193

Earlier quoted context omitted.

> This is NOT true with C++, absent template metaprogramming... So it is true in C++ then, right? It's only not true in "C++ minus templates" which is a language no one uses.

Introducing template metaprogramming comes with its own passel of problems: compile times (and code size) can explode, and then there are the difficult-to-debug error messages if you screw up. Because Smalltalk uses latent types, these decisions are deferred till run time, which is a loss for static analysis, but doesn't require a separate generated bit of code for every combination of arbitrary types used in the pro…

I've never seen a C++ codebase without templates in my life.

Re: Inheritance Often Doesn't Make Sense

#194
post #164

Earlier quoted context omitted.

Sure. I want a vehicle to go to work. A car, preferably, but a motorcycle or bus will do too in a pinch.

I don't know about this. Is a teleporter a vehicle? What about a vehicle which doesnt have wheels, in a world built around assuming that vehicles have wheels?

>I don't know about this. Is a teleporter a vehicle?

Depends on your definition on vehicle. For many purposes (e.g. going somewhere) it could be, especially if it also existed.

Subtyping just means "having a taxonomy of things, where we can substitute things lower on the taxonomy -- more concrete, more specialized and so on" with things higher up when wanting less abstraction (and vise versa).

And this is pretty much the case with the world -- Plato's "ideas", scientific taxonomies (e.g. of animals and plants), or RDF and semantic taxonomies, and so on are all based on the same concept.

(That doesn't mean they're perfect descriptions of the world, like our class taxonomies in OOP don't lead to perfect descriptions of most problem domains either).

>What about a vehicle which doesn't have wheels, in a world built around assuming that vehicles have wheels?

That's a problem of definition of what should belong in the class of things we call "vehicle" (and you could have the exact same questions when doing OOP).

As such it's not an argument in whether the real world has or doesn't have subtyping.

Re: Inheritance Often Doesn't Make Sense

#195
post #179

Earlier quoted context omitted.

Which is also why these modern cars have turned a minor belt failure into an expensive catastrophic failure, often destroying much of the engine. I'd hardly call it a design to aspire to. I'd probably compare it more closely with a system where everything receives a mutable God object.

He's describing the accessory belt. You're referring to the timing belt.

This description and definition discussion describes very well the definition lawyering and specsheet-rewritting that agile avoids, by having the walking specsheet (customer) sitting in during the creation process.

Re: Inheritance Often Doesn't Make Sense

#196

If you ever open the hood of a modern car and look around a bit you'll discover that at the front there's a half dozen pullies connected to one or more belts. Each of these pullies is connected to some diffeerent system each able to turn rotational acceleration into a useful service. The alternator converts that rotational energy into electricity. The AC unit uses it to operate a heat pump. The coolant and oil pumps…

What you are describing is an interface, not inheritance. They are implementing an pulley interface, not inheriting a specific pulley implementation from a common housing or something.

The distinction between "implementing" an interface and "inheriting" a base class is largely just a Java-ism.

To some extent, it's a distinction without a difference - at a semantic level, Java only distinguishes between interfaces and purely abstract base classes because one allows multiple inheritance and the other doesn't, and the separate "inherits" and "implements" keywords flow from there. Other languages (like C# and Kotlin) distinguish between interfaces and overridable classes for the purposes of deciding when to allow multiple inheritance, but use the same syntax and terminology for inheriting from both interfaces and base classes. Still other languages make no structural distinction, but still use the word "interface" to refer to base classes that don't include any implementation, and therefore aren't so susceptible to the diamond inheritance problem. TBH, I think the Java-style treatment is the least conceptually consistent, since it's entirely possible to "inherit" a base class without inheriting a single bit of information, either because everything it declares is abstract or because everything got overridden.

There's a pretty decent coverage of all the grotty details of this concept space, and how different languages treat it, in the beginning of the gang of four book.

Re: Inheritance Often Doesn't Make Sense

#197
post #179

Earlier quoted context omitted.

Which is also why these modern cars have turned a minor belt failure into an expensive catastrophic failure, often destroying much of the engine. I'd hardly call it a design to aspire to. I'd probably compare it more closely with a system where everything receives a mutable God object.

He's describing the accessory belt. You're referring to the timing belt.

Yes, the timing belt or timing chain is inside the engine casing and it can be bad when it or subordinate parts fail. Though a timing belt/chain failure causing a catastrophic event for the engine itself, I don't think that's very common. What I'm referring to is called the serpentine belt and is often accompanied by what's called an accessory or AC belt.

Re: Inheritance Often Doesn't Make Sense

#198

Earlier quoted context omitted.

What you are describing is an interface, not inheritance. They are implementing an pulley interface, not inheriting a specific pulley implementation from a common housing or something.

The distinction between "implementing" an interface and "inheriting" a base class is largely just a Java-ism. To some extent, it's a distinction without a difference - at a semantic level, Java only distinguishes between interfaces and purely abstract base classes because one allows multiple inheritance and the other doesn't, and the separate "inherits" and "implements" keywords flow from there. Other languages (like…

Thank you. I came up in C++ land where the distinction between interfaces, abstract classes, and base classes is pretty muddy.

Re: Inheritance Often Doesn't Make Sense

#199

Earlier quoted context omitted.

Introducing template metaprogramming comes with its own passel of problems: compile times (and code size) can explode, and then there are the difficult-to-debug error messages if you screw up. Because Smalltalk uses latent types, these decisions are deferred till run time, which is a loss for static analysis, but doesn't require a separate generated bit of code for every combination of arbitrary types used in the pro…

I've never seen a C++ codebase without templates in my life.

Template meta-programming is a different usage from template generics. It has a higher compile time cost because it performs computations as a side-effect of compilation.

Re: Inheritance Often Doesn't Make Sense

#200
Here are some harder examples-

abs(x) + abs(y) = 1 is a square of side 1.

x^2 + y^2 = 1 is a circle of radius 1.

But abs(x) = positive sqrt(x^2)

so squares and circles ought to have the same 2D parent, since given the x & y, its just a matter of applying the right transform.

y = ax^2 + bx is a parabola through the origin.

y = bx is a line through the origin.

so lines and parabolas ought to have a common 1D curve as a parent, because a parabola reduces to a line when a=0.

clearly a line shifted by a constant is still a line.

so also, a line rotated clockwise or anti clockwise through say 90 degree is still a line.

so then i take a horizontal line, shift it once and rotate it twice, join these 4 lines and get a square.

so squares ought to be a container type with 4 lines ? or wait, if i collapse the two verticals ie. set the height to 0, then a square is just a straight line with no height, which is absolutely true geometrically, but think about the damage you’d do to your type-theory.

but didn’t we just say lines are just degenerate parabolas. so then we ought to be able to take a square, grab its 4 sides which are lines, transformed each line into a parabola, and tell me what that gives you.

and you haven’t even gotten me started on activation functions. since all logistics are richards curves, a gompertz is just a particular richards. so then a relu should inherit from a gompertz and a swish should be a child of relu and somewhere in here we need the hyperbolic tangent, either as a parent or a child or a sibling or the notorious c++ friend function.

now go ask your friendly neighborhood tensorflow colleague why the activations don’t share a common parent, why lines aren’t parabolas and squares aren’t lines and so in and do forth.

Post reply on HN