Live data from Hacker News

CSS Classes Considered Harmful

keithcirkel.co.uk

21–28 of 28 posts

Re: CSS Classes Considered Harmful

#21
CSS suffers from the lack of composability and organizational features found in modern high level programming languages. If your excited about modern css features like "is" or "has", then you agree it needs more functions to keep up with customer demand.

I wrote a bit about this problem from the perspective of a clojure and clojurescript developer on my blog. https://drewverlee.github.io/posts-output/2021-8-26-css-opti...

The reason, clojure and clojurescript is relevant is those programming languages can easily compile to css, allowing users to easily add pl features that don't exist in css and not force devs to learn the same concepts twice. It can do this becuase as a lisp, turning clojure native hashmaps into classes (or attributes if you prefer) is like pouring water into a container. We numerous libs to do this in the clojure ecosystem, here is a reddit discussion around the newest one: https://www.reddit.com/r/Clojure/comments/w56tg8/shadowcss_c...

Though i would personally opt for the slower page perf and faster dev performance of just using cljs compiled to inline-styles solution, as i suggest in my blog.

Of course there might be performance benefits to coding at the lower css level directly, but on average that's not a good tradeoff for most teams i have worked on. s

Re: CSS Classes Considered Harmful

#22

Wish this article dedicated time to considering whether widespread use of attribute selectors will slow down the browser, but it doesn't seem to. CSS class selectors have been aggressively optimized by browser vendors for decades, vs. selectors that just filter on an arbitrary set of HTML attributes. Modern devices are pretty fast though, so maybe it's not an issue - but I know in the past the cost of doing CSS rule…

I considered exploring it but css selector performance just doesn’t matter with todays engines. There are far greater issues, and far better performance wins than “optimising your selectors”.

Makes sense, I would just worry that if I built my whole stack around this, suddenly I hit a breakdown point where I have a ton of attribute selectors and now adding new DOM elements to a content view takes a millisecond.

I'm more wary about this than I used to be since someone managed to accidentally cause tsc to need multiple seconds to compile a single file by making a small change to a type definition. Big O still can bite you!

Re: CSS Classes Considered Harmful

#23

A catalogue of errors one can implement with CSS classes (as easily as using other CSS selectors) and of bad solutions to nonexistent problems. On top of that, a strange attitude: apart from the embarrassing argument that "old" technology is bad, the author assumes that HTML is written by hand, apparently by a team of monkeys taking pride in the intensity of their fuzz testing, rather than generated correctly from te…

Sounds like you're heavily invested. I found the piece interesting. CSS is far from perfect and could definitely use a rethinking once in a while.

Re: CSS Classes Considered Harmful

#24
post #9

The article did a good job of explaining the problem of codifying a style ontology using only clases, and proposing a solution to that problem (custom attributes and pseudo selectors for specialization). It did not convince me that classes themselves were bad, and replacing them with custom tags doesn’t seem to solve anything. The main argument advanced against classes (as opposed to certain ways of using classes) se…

The main problem (as described) is that CSS classes don't take parameters. Imagine coding in Foolang and its classes don't take parameters, resulting in class explosion.

Author goes on to show how to give them parameters, news at 11. ;-)

Re: CSS Classes Considered Harmful

#25

A catalogue of errors one can implement with CSS classes (as easily as using other CSS selectors) and of bad solutions to nonexistent problems. On top of that, a strange attitude: apart from the embarrassing argument that "old" technology is bad, the author assumes that HTML is written by hand, apparently by a team of monkeys taking pride in the intensity of their fuzz testing, rather than generated correctly from te…

I don’t recall saying old technology is bad. I was more trying to say it served its purpose at the time but as websites have gotten more complex we’re still relying on this one single primitive. It’s true that as systems scale often templating systems are introduced to alleviate writing html, but these systems are rarely complete which means developers - meeds unmet - need to “drop down a layer” and in that should be…

Great article. Shouldn't have been flagged; I think a few folks pride was hurt.

However, there's a foot-gun in the first paragraph. In the mid-nineties practically no one was using "black and white" monitors. I remember a few ancient DOS test-only stations at a school and a single amber-monochrome hardware terminal (connected to big-iron at work) in that time period. Everything else doing real work was Win3.1 and color Mac by then. Netscape browser had already dropped and was popular; no one was using it in black and white.

This was in California. May be slightly ahead, and I'm not taking developing countries into account. But color was so compelling it was already not-uncommon by the late 80s.

Re: CSS Classes Considered Harmful

#27

So...the problem with css classes is that they are old? I'm not sure I quite understand the why . Data-attributes on html elements are only for JS behavior in my usage, and CSS classes are for styling.

No, it's because they don't take parameters. Parameters are supported in the tag itself however, might as well use them.

Re: CSS Classes Considered Harmful

#28

Earlier quoted context omitted.

I don’t recall saying old technology is bad. I was more trying to say it served its purpose at the time but as websites have gotten more complex we’re still relying on this one single primitive. It’s true that as systems scale often templating systems are introduced to alleviate writing html, but these systems are rarely complete which means developers - meeds unmet - need to “drop down a layer” and in that should be…

Great article. Shouldn't have been flagged; I think a few folks pride was hurt. However, there's a foot-gun in the first paragraph. In the mid-nineties practically no one was using "black and white" monitors. I remember a few ancient DOS test-only stations at a school and a single amber-monochrome hardware terminal (connected to big-iron at work) in that time period. Everything else doing real work was Win3.1 and col…

Was a poor attempt at a joke that perhaps didn’t carry :p
Post reply on HN