Profile picture
Sarah Mei @sarahmei
, 10 tweets, 2 min read Read on Twitter
I have many Opinions on this, as a mostly-backend software developer who spent the last decade doing increasing amounts of JavaScript, and then the last year firmly in the land of CSS.

My first opinion: Amber is completely right.

I used to be one of those people.
However, I get why the CSS cascade is hard. And it starts with the fact that the cascade is structurally equivalent to inheritance.

Even in backend code, inheritance is a tricky technique to use well, & overuse leads to badly-partitioned code and/or shittons of conditionals.
But there are crucial differences, as well, between the cascade and inheritance, that make it hard to directly apply to CSS the techniques we use in backend code to manage the difficulties of inheritance.
For the purposes of the cascade, a webpage is a tree - just like a class hierarchy is a tree. Styles applied to root nodes (like logic in base classes) get passed down to child nodes (which are like subclasses).
In the cascade, a child node may have styles applied directly to it, which override the styles it gets from its parent. This is like a subclass redefining a method defined in its superclass to provide some specialized behavior.
One reason that devs with inheritance experience tend to think that CSS is “broken” is because the way the styles for a node are resolved can strongly resemble multiple inheritance - a bugaboo concept that the object-oriented literature advises you in VERY strong terms to avoid.
In OO-land, multiple inheritance refers to any hierarchy where a subclass is receiving shared logic from more than one source.

In Ruby, for example, when creating a class, you can’t give it more than 1 parent class, but you _can_ include modules, for a similar effect.
This isn’t inherently awful, but it can turn bad quickly if it makes it hard to tell what happens when you call a method on an object. Let’s look at an example.
(uhhh, in a little while, because rn I need to take a walk with the kids😅) to be continued :)
This was a really long “walk” 😅 but I’ll get back to this thread later today! You’re witnessing twitter at the speed of parenting😬
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Sarah Mei
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!