Live data from Hacker News

If Inheritance is so bad, why does everyone use it?

buttondown.email

301–310 of 389 posts

Re: If Inheritance is so bad, why does everyone use it?

#301

Nobody calls it this, but cascading styles in CSS is just like inheritance and I think should be avoided for all the same reasons. I feel it's a big part of why CSS at scale becomes unmaintainable. There isn't even a built-in way to compose two classes together if you want to avoid cascading/inheritance. It looks like composition over inheritance has caught on as the better default in other languages, but in the CSS…

It's because people don't understand cascade we end up with pages that have text in 18 different font sizes. Cascade was a brilliantly simple idea and gave great consistency of design easily. At the time it was great. I believe the only reason most people are mad at CSS is because specificity is hard to grasp and order-dependent resolution and you don't control it when you bundle 500 packages. You get scores of megab…

> It's because people don't understand cascade we end up with pages that have text in 18 different font sizes.

Variables and/or utility classes mostly solve this so not sure how it's related.

> Since then we've got more tools to control cascade: layers, scopes, inherit/initial/revert/revert-layer/unset for every property, etc. But people still insist on inline styling. I get it, it's much simpler. But they will keep being unhappy until they learn cascade and stop fighting tools. Yes, learning takes effort but so does resistance.

Similar to inheritance-like features in other languages, I have learned it and find composition is the better default. It's too complex for too little benefit so I avoid it wherever possible.

I find maintainable CSS approaches are all about reducing the blast radius of style inheritance. So people are writing maintainable in sprite of cascading, not because cascading helps.

> specificity is hard to grasp and order-dependent resolution

Specificity is another foot-gun to avoid for me. It's learnable, yet easy to forget later. When you're tempted to rely on specificity there's usually a more readable way to do it that's not going to bite you later.

Do you doubt the developers behind Tailwind library understand specificity and the cascade? They clearly must understand it, use it where it helps, and avoid it where it doesn't.

Re: If Inheritance is so bad, why does everyone use it?

#302
post #297
post #286

Earlier quoted context omitted.

But why would you want to be able to pass an apple to a function expecting a banana? Doesn't even make sense, the whole point is that the type system forces you to consider this stuff. If OP wanted to be allowed to do whatever and just have the software fail at runtime, JS is right there.

> But why would you want to be able to pass an apple to a function expecting a banana? I would never. I know that I'm holding a banana, I want to pass it to a method that receives a banana. But what I can't do is put my banana through a rotateFruit function first, because then Java will forget that it's a banana and start treating it as a fruit.

Java has generic functions since forever, something like ` T rotateFruit(T fruit)` would return your banana typed object just fine.

Re: If Inheritance is so bad, why does everyone use it?

#303

Earlier quoted context omitted.

You can have encapsulation without oop. Polymorphism is the real benefit of oop imho

> Polymorphism is the real benefit of oop imho It's pretty much the definition of OOP. The core feature of OOP is just bundling functions with the state it processes. When you bundle state and functions together, you can't predict what calling the function will do without knowing both the code and state. You can say its 'the real benefit', I guess, but that feels like circular reasoning. Its pretty much the definitio…

> You can say its 'the real benefit', I guess, but that feels like circular reasoning. Its pretty much the definition of what OOP is, so calling it a benefit feels weird.

It's a benefit compared to how people were writing code before it became mainstream (for polymorphism: by jumping to data-defined parts of the code and hoping for the best, and for encapsulation: subroutines working on global variables).

Re: If Inheritance is so bad, why does everyone use it?

#304

Earlier quoted context omitted.

Avoiding the cascade at all costs, for example. It can introduce a lot of unintended consequences. Another anti pattern I have seen is the over use of media queries to force the browser to do certain things rather than embracing relative sizing constraints via intrinsic design and letting the flexbox and grid algorithms do most of the heavy lifting. Here though I want to point out isolation is relative, as is the cas…

To be fair, there was a time that flexion did not exist and extensive use of media queries was the only way to create a responsive website. Those efforts don't just dissappear quickly, since that was the only way available that worked across all browsers for nearly a decade.

Isn’t the browser responsive by default? The only issue I see is taking a layout built for refloyable documents and wanting to create applications and magazine-like design with it. Now it’s possible but it’s always more convulated than something like the tools available on platforms like iOS and Android.

Re: If Inheritance is so bad, why does everyone use it?

#305
post #80

It seems like protocols solve 90% of the problems that inheritance does, but with 10% of the headaches. Instead of trying to ensure that two types can both be passed to a function that only knows about the parent type, just have a parameter that says "Whatever's passed has to conform to this, I don't care what it is otherwise."

Nice in principle, but doesn't it make it quite difficult to analyze such code? E.g. finding places that use a particular function of a protocol.

I recall Pyright for Python is not able to find such call sites. But perhaps there are better implementations of the concept?

Re: If Inheritance is so bad, why does everyone use it?

#306

Earlier quoted context omitted.

It's because people don't understand cascade we end up with pages that have text in 18 different font sizes. Cascade was a brilliantly simple idea and gave great consistency of design easily. At the time it was great. I believe the only reason most people are mad at CSS is because specificity is hard to grasp and order-dependent resolution and you don't control it when you bundle 500 packages. You get scores of megab…

> It's because people don't understand cascade we end up with pages that have text in 18 different font sizes. Variables and/or utility classes mostly solve this so not sure how it's related. > Since then we've got more tools to control cascade: layers, scopes, inherit/initial/revert/revert-layer/unset for every property, etc. But people still insist on inline styling. I get it, it's much simpler. But they will keep…

Cascading does help. When you want to design a document. If you want an application like interface or the same constraints as a magazine page, cascading is the wrong tool for the job. Design tools don’t use it. Layout engines for GUI don’t use it. Flex and Grid is far from the constraints based interface builder in iOS.

Re: If Inheritance is so bad, why does everyone use it?

#307
post #147

Earlier quoted context omitted.

> "I/We failed with " never generalizes to " " is bad. I thought the same for decades, then I met Groovy and Grails. Of course, it’s not bad in an absolute sense (IMHO that doesn’t make any sense), but when some problem can be found only at runtime, when any proper compiler would catch that compile time, it’s hard to argue that it’s a good direction. Especially when TypeScript made it quite obvious what’s possible on…

> TypeScript made it quite obvious what’s possible only with simple type checking. Typescript's type system is anything but simple.

[deleted]

Re: If Inheritance is so bad, why does everyone use it?

#308
post #302
post #297

Earlier quoted context omitted.

> But why would you want to be able to pass an apple to a function expecting a banana? I would never. I know that I'm holding a banana, I want to pass it to a method that receives a banana. But what I can't do is put my banana through a rotateFruit function first, because then Java will forget that it's a banana and start treating it as a fruit.

Java has generic functions since forever, something like ` T rotateFruit(T fruit)` would return your banana typed object just fine.

Inheritance is just a tool, that you use if it fits you software architecture. You use other tools, like generics, interface, where it makes senses to ise them. I think people wants the one true way to not have to design their software. And when they use inheritance in a ways that does not fit, they blame inheritance.

Re: If Inheritance is so bad, why does everyone use it?

#309

I feel people don't understand what inheritance and (object orientation in general) is useful for, misuse it, and then it gets a bad reputation. It's not about making nice hierarchies of Cars, Fruits, and Ovals. For me the main point is (runtime) polymorphism. E.g. you have a function that takes a general type, and you can pass multiple specific types and it will do the right thing. And if you want to avoid huge if-e…

If people get it wrong so regularly, what value is it providing as a concept? These concepts are supposed to help us reach something better, if you have to add 30 caveats to every part of it, all it did was hide its own complexity from you, instead of managing it for you.

Because the tree is a nice abstraction for some problems. But sometimes you need a collection of pure functions. Sometimes it’s best to think of your object as data blobs going through a line of map,filter,reduce functions. Not every part of your application is the same, use the right abstraction for the job.
Post reply on HN