Live data from Hacker News

CSS now has an if() conditional function

caniuse.com

191–200 of 245 posts

Re: CSS now has an if() conditional function

#191
post #51

Earlier quoted context omitted.

Probably not. There is a lot of optimizations browsers do to make the stylesheets super fast[1], and I think quite a few of those rely on CSS not being Turing complete. 1: https://hacks.mozilla.org/2017/08/inside-a-super-fast-css-en...

CSS is Turing complete :-) You can find pure-CSS implementations of Game of Life, for instance.

The implementations I have seen rely on the inclusion of HTML form elements, and a manual step to update the state.

So in that sense CSS + HTML + User Interaction is Turing complete. But that is a different language then CSS, even if a part of that language happens to be written in CSS.

Re: CSS now has an if() conditional function

#192

Earlier quoted context omitted.

Conditional expressions are declarative. For example, every template language worth its salt has conditionals. A programming (i.e Turing complete) language requires recursion or a construct of equal power.

There is no recursive program that can't also be created by adding in more conditionals. It's turtles the whole way down.

You can't add all possible conditionals for every kind of loop/iteration, such as dynamic and infinite.

Re: CSS now has an if() conditional function

#193

Earlier quoted context omitted.

I find lisp to be a very non ergonomic language and am happy that python is the default.

Can you quantify that?

Let's just say that the weights of opening and closing parentheses do not cancel out.

Re: CSS now has an if() conditional function

#194
post #61
post #42

Give it enough time, every declarative language becomes a programming language. This is happening with all config files, markup languages, data formats. The distinction between code, config and data is being erased. Everything is a soup now. Data is application, configuration is code. Code is an intermediate, volatile thing that is generated on the fly and executed in the temporary lambda containers.

This is so true, I have seen it happen with so many projects. It always starts with a cute declarative DSL, and inevitably imperative / flow control structures emerge, at which point you wonder why they didn't use a real programming language in the first place and save you the hassle or learning a half baked imperative DSL. - Puppet - CMake - Terraform - ... All these started with pure declarative DSL then incrementa…

People love to hate on Maven's XML but at least it's been mostly the same since 2006. There are conditionals in profile activation expressions but they are very limited by design. Declarative done right, IMO

Re: CSS now has an if() conditional function

#195
post #42

Give it enough time, every declarative language becomes a programming language. This is happening with all config files, markup languages, data formats. The distinction between code, config and data is being erased. Everything is a soup now. Data is application, configuration is code. Code is an intermediate, volatile thing that is generated on the fly and executed in the temporary lambda containers.

> every declarative language becomes a programming language. Overly pessimistic, lots of non-programming languages remain non-programming languages. Just because one of the most widely used declarative languages start adding conditionals doesn't mean the whole world is turning upside down... > The distinction between code, config and data is being erased. As as lisp programmer, I love it. Get rid of treating things d…

A gentle reminder: conditionals aren't new to CSS; @supports and @media are conditionals; so are style queries.

if() just codifies behaviors and hacks [1] developers were already doing.

[1]: https://lea.verou.me/blog/2020/10/the-var-space-hack-to-togg...

Re: CSS now has an if() conditional function

#196

Earlier quoted context omitted.

> Just because one of the most widely used declarative languages start adding conditionals doesn't mean the whole world is turning upside down. The question still is: why is CSS becoming a programming language? And who decides on this, anyway?

Becoming? CSS is already Turing-complete ( https://stackoverflow.com/a/5239256 ), even without if() function. Why? Because of enormous JS bloat. Pure CSS solutions are more performant and backwards-compatible (don't raise exceptions which abort the code). Who decides? CSS Working Group.

Or they are performant now. But once people start writing CSS code the same way the write JS code, they stop to be. You can still write super-tight code in ASM (or eve C) and it will be blazing fast. Almost nobody does it, because it's too hard. Once people start writing CSS the same way, it'll become slow and bloated too.

Re: CSS now has an if() conditional function

#197

Earlier quoted context omitted.

> Just because one of the most widely used declarative languages start adding conditionals doesn't mean the whole world is turning upside down. The question still is: why is CSS becoming a programming language? And who decides on this, anyway?

The web should always have been a programming language, with all the usual constructs available in both the display and markup layers. But instead of a single unified standard library for the industry we got a sprawling, ludicrous mess of multiple poorly thought-out semi-compatible technologies, with an associated sub-industry of half-baked fixes and add-ons.

As always, hindsight is 20/20, but when you're living it, the half-baked decisions and add-ons are a product of you figuring it out on the fly. You don't have the knowledge of which proposal will solidify into an industry standard, and you don't know which vestigial implementations will be a nightmare for backwards compatibility down the line.

The context is also lost. Javascript was famously coded in a day or whatever and called 'javascript' not ecmascript as marketing to compete with Java. Besides that well known case there's presumably thousands of esoteric business decisions made back then which shaped the "sprawling, ludicrous" landscape, and which are now lost to time.

Yes, the web should have always been a programming language. And the flying cars of 23xx should have never used a z-debuffer doodad.

Re: CSS now has an if() conditional function

#198
post #61
post #42

Give it enough time, every declarative language becomes a programming language. This is happening with all config files, markup languages, data formats. The distinction between code, config and data is being erased. Everything is a soup now. Data is application, configuration is code. Code is an intermediate, volatile thing that is generated on the fly and executed in the temporary lambda containers.

This is so true, I have seen it happen with so many projects. It always starts with a cute declarative DSL, and inevitably imperative / flow control structures emerge, at which point you wonder why they didn't use a real programming language in the first place and save you the hassle or learning a half baked imperative DSL. - Puppet - CMake - Terraform - ... All these started with pure declarative DSL then incrementa…

What's the old adage? Software expands until it can send email?

Re: CSS now has an if() conditional function

#199

Earlier quoted context omitted.

> every declarative language becomes a programming language. Overly pessimistic, lots of non-programming languages remain non-programming languages. Just because one of the most widely used declarative languages start adding conditionals doesn't mean the whole world is turning upside down... > The distinction between code, config and data is being erased. As as lisp programmer, I love it. Get rid of treating things d…

A gentle reminder: conditionals aren't new to CSS; @supports and @media are conditionals; so are style queries. if() just codifies behaviors and hacks [1] developers were already doing. [1]: https://lea.verou.me/blog/2020/10/the-var-space-hack-to-togg...

[deleted]

Re: CSS now has an if() conditional function

#200
post #69

I'm pretty happy to see this, as conditionals can really help keep code manageable when trying to define CSS variables or other properties based on combinations of light mode, dark mode, high-contrast, contextual state in a document or component, etc. if() isn't the only way to do this, though. We've been using a technique in Review Board that's roughly equivalent to if(), but compatible with any browser supporting C…

I recently implemented dark/light mode for the first time and was really surprised to find that in order to add a toggle I had to duplicate a both of vars/styles and use JavaScript. I'm looking forward to not having to deal with that cruft in the future.
Post reply on HN