DEV Community

Discussion on: Why is CSS Hated On?

Collapse
 
facundocorradini profile image
Facundo Corradini

Cause it's out of their expertise. And even alien to their main way of thinking.

CSS has a logic behind it, but it's declarative nature makes it closer to linguistics than to the logical mindset of imperative programming or the spatial thinking of design.

People hating on CSS are either programmers or designers that are trying to shoehorn it into their way of thinking instead of taking the language for what it is: a language.

CSS describes the interface, provides suggestions for the browsers that at the end of the day have the final word on how things are rendered.
That is very different from drawing in a known-dimensions, fixed canvas as designers normally do, and even quite different from the set of logical instructions we write in traditional programming

Collapse
 
gabrielpedroza profile image
Gabriel Pedroza

That is very true and I didn't really think about that because truly, CSS is incomparable to any other language, whether programming or not. However, I do think CSS leans a lot more on rules and understanding on how some things just work than logic unless you are using SASS and making functions and for loops. Overall, thank you for explaining some things I didn't really consider when writing this ❤️

Collapse
 
facundocorradini profile image
Facundo Corradini • Edited

Yeah, it's not like CSS is directly comparable to a spoken language, but the mechanism behind it are. Linguistic intelligence is linked to pattern and contexts recognition.

In all spoken languages a given word can have different meanings based on the context. Think for instance the word "lead". Without context, you can't really know what it means. You can't even know how to pronounce it.
Is it a lead as in “being in the lead”, the best position in a race? Maybe it’s lead, the toxic, radioactive metal we used to have in our house’s plumbing It may not even be meant as a noun but an adjective, as in "lead developer", meaning you’re in charge of the group. Or maybe as one of the 40 ways it’s used as a verb.

That same thing happens with CSS. A given instruction can mean a million different things, depending on the stacking context, the display property, block formatting context, etc.. even the relation of the given element with its siblings, parents and childs.

In CSS, just like in a spoken language, context is everything

Thread Thread
 
gabrielpedroza profile image
Gabriel Pedroza

I do understand what you mean by CSS needing context but from my current knowledge, it is not an absolute deal-breaker if you don't have any preconceived knowledge or context to it. For example, I can have about 5 props to this specific class selector and I can more or less depict what is happening to it. Granted, I will not know where or how it looks in the viewport because other selectors like the parent will have a direct impact on it but I am not totally in the dark of it either.

Thread Thread
 
facundocorradini profile image
Facundo Corradini

You can with a rule such as "color: red". The color is going to be red, unless overwritten in a high-specificity selector or something that takes priority on the cascade.

But how about something like "flex-basis: 200px"... that doesn't tell you anything on its own. Doesn't even tell you if it's width or height, as it would depend on the flex-direction. Doesn't really tell you how big it's going to be, as that would depend on the siblings' flex-basis, their flex shrink and flex grow values, the container width, the margin, padding and box-sizing, etc

Actually, it doesn't even tell you if it's going to do anything at all, as that depends on whether the parent is a flex container or not.

Thread Thread
 
gabrielpedroza profile image
Gabriel Pedroza

Yeah, now I do understand what you mean by CSS being extremely dependent on context. Now you saying that, it dawns on me that every single property could have the potential of not working if the html elements have inline-styles to it. Thank you for going out of your way and truly explaining this to me

Collapse
 
etienneburdet profile image
Etienne Burdet

Exactly, lot of people will disregard CSS as "not true programming", only as as strategy to hide the fact they can't use it properly when they face it.

I love the linguistic analogy. Everybody knows how to write, not everybody is Shakespear though… There is beauty to CSS (or similar declarative languages like LaTeX) and it's harder than it looks to find a simple, maintainable solutions, but it's a super efficient way of programming actually (entirely stateless!).

Now there is a second thing people hate: CSS is messed-up by three decades of browsers evolution. Some people will mix that reality—it's not a perfect world—with to dismiss the premise of the language—a declarative, stateless way to style.