News for hackers. Stuff that matters.
Re:Custom Properties as State by bawolff on Friday January 08, 2021 @10:42PM (#25696501)
I'm not sure what is so special about using css custom properties (aka css variables) as well, variables. That is their intended purpose after all, what else would you use them for?

In fairness the author talks about using them very dynamically (rip cache), which is a bit different, but still its just an extension of the basic idea of setting a variable.

Re:Custom Properties as State by brundolf on Saturday January 09, 2021 @12:04AM (#25697314)
One of the wonderful things about CSS is that because it's a domain-specific language, it can afford to be 100% declarative, with 100% deterministic behavior, and doesn't need any exceptions to be made or trap-doors to be added. The trap-door is JavaScript.

So, the more things you can move over into CSS, the more things exist in this beautiful pure context that's highly debuggable thanks to modern browser tooling (and that's not even getting into the performance advantages vs doing things in JS).

Put simply: it's really exciting every time CSS gets a new "real programming language" feature, even if these things are basic and familiar in other programming contexts. In this case we're not really getting a "new" feature, but people are used to thinking of CSS variables as like, a theming mechanism. I for one had never thought to use them as an API data format. The author is probing the boundaries of what's possible to do with them, and that's exciting and interesting.

As an aside: there's also a huge community that loves to just push and abuse HTML/CSS as far as they can for the sport of it. CSS-Tricks and its sibling-site CodePen are at the center of that community. To people like that, the idea of an API endpoint that uses a stylesheet to relay raw data for arbitrary usage is pretty cool.

Re:Custom Properties as State by saurik on Saturday January 09, 2021 @02:26AM (#25698332)
If you add enough "real programming language" features, aren't you going to lose the "wonderful thing" you cite about CSS?
Re:Custom Properties as State by brundolf on Saturday January 09, 2021 @10:32AM (#25701123)
Not if you don't add state/control flow. That's the key. That stuff is exiled to JS-land.

And by "state" I mean it in its proper sense: something where CSS itself can mutate its own state. The OP calls CSS custom properties "state", but they're really just "constants" in the context of CSS itself (they can only be mutated by JS).

Re:Custom Properties as State by bawolff on Saturday January 09, 2021 @05:46PM (#25705812)
I'd argue that css already has (very limited) control flow [calc() statements, and the cascading nature of selectors]. In combination with user interaction and html, it also has state.

For example see the css implementation of celluar autonoma http://eli.fox-epste.in/rule110/

Re:Custom Properties as State by brundolf on Sunday January 10, 2021 @11:50AM (#25716543)
CSS has expressions, but not imperative logic or mutability (it's possible I misused the term "control flow")

You're right that HTML (technically, the DOM) has a little bit of intrinsic state, despite our mental model of it being static. However that state is constrained to user interaction and is always very localized, so it avoids most of the maintainability problems that we think of as coming from having mutable state

Re:Custom Properties as State by valenterry on Saturday January 09, 2021 @03:04AM (#25698547)
Yes, at some point. Check out, for example, dhall (https://dhall-lang.org/) to see where the sweet spot lies.
Re:Custom Properties as State by pavlov on Friday January 08, 2021 @11:14PM (#25696829)
A lot of web front-end development these days is just very elaborate costume parties for global variables.
Re:Custom Properties as State by arthurcolle on Friday January 08, 2021 @11:26PM (#25696969)
wait until you hear about the song and dance needed for a modern React app
Re:Custom Properties as State by bawolff on Friday January 08, 2021 @11:49PM (#25697182)
That's my point though, react has an actual song and dance. This is literally just using a feature literally named "variables" to store data, as if it was like a variable or something.
Re:Custom Properties as State by rriepe on Saturday January 09, 2021 @12:08AM (#25697351)
> (rip cache)

You'd have a separate theme.css that defined the new variables. Because of CSS variables you can keep the main style.css and all the markup the same.

Re:Custom Properties as State by bawolff on Saturday January 09, 2021 @12:31AM (#25697570)
True, but you still cant do first paint until all css is loaded, and for people with fast connections, the latency of the extra roundtrip matters more than the size of the file downloaded (within reason)
Re:Custom Properties as State by bryzaguy on Sunday January 10, 2021 @03:13PM (#25719137)
An alternative would be keeping theme state in JS as suggested at the end of the article which improves the cache-ability of the css file as themes change.
Re:Custom Properties as State by rriepe on Saturday January 09, 2021 @01:16AM (#25697895)
Yeah you'd have to load it in async to avoid that. You could start with a gray base and have the theme color pop in. Flash of original color.