Live data from Hacker News

CSS now has an if() conditional function

caniuse.com

221–230 of 245 posts

Re: CSS now has an if() conditional function

#221
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.

So why do people still design declarative languages?

> So why do people still design declarative languages?

Cost.

If money were no object, you would only hire people who can troubleshoot the entire stack, from React and SQL all the way down to machine code and using an oscilloscope to test network and power cabling.

Or put another way, it would be nice for the employer if your data analyst who knows SQL also knew C and how to compile Postgres from scratch, so they could fully debug why their query doesn’t do what they expect. But that’s a more expensive luxury.

Good software has declarative and imperative parts. It’s an eternal tradeoff whether you want the convenience of those parts being in the same codebase, which makes it easier to troubleshoot more of the stack, but that leads to hacks that break the separation. So sometimes you want a firm boundary, so people don’t do workarounds, and because then you can hire cheaper people who only need to know SQL or React or CSS or whatever, instead of all of them.

Re: CSS now has an if() conditional function

#222
post #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.

You can do without javascript. Checkbox `:checked` + `label` trick for toggling states still works.

See: https://codepen.io/abdus/pen/bNpQqXv

Re: CSS now has an if() conditional function

#223

Earlier quoted context omitted.

Can you quantify that?

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

You would need to show that, including the parens, the average Lisp program requires more tokens than Python.

I'm not sure that's true. Because Lisp has a lot of facilities for writing more concise code that are difficult to achieve without the parens.

Re: CSS now has an if() conditional function

#224

Earlier quoted context omitted.

That's actually what two ifs could be.

Was the case against the goto statement so good we can't mention it?

More or less, I meant how this would be inlined in assembly with a goto that could goto back where the branching originated from.

Re: CSS now has an if() conditional function

#225
post #81

Earlier quoted context omitted.

align-content: center; (supported on block elements since sometime last year)

Thanks, seems to work at first sight in combination with text-align for the horizontal alignment! That means I may finally not need line-height or multi-element tricks for this anymore Interesting that this is finally there since a year! I wonder what made them decide to support it finally, since CSS's creation in 1996. A button never looks professional if the text in it isn't centered, this was a really needed featu…

> The items are packed flush to each other in the center of the alignment container along the cross axis

You're right, the entire Values section seems to still be worded exclusively for flexboxes. The description at the top adds "or a grid or block-level element's block axis".

Re: CSS now has an if() conditional function

#226

Earlier quoted context omitted.

If only Lisp had better presense in modern code editors. Emacs is not enough, especially on Windows where it is super slow. I think this is what actually stops newcomers to start with Lisp and not Python

My crackpot theory is that what stops newcomers is how unergonomic "(" and ")" are to type on typical keyboards. If mainstream lisp dialects used square brackets instead, we'd all be programming in it!

> If mainstream lisp dialects used square brackets instead, we'd all be programming in it!

You've almost convinced/nerd-sniped me to write a(nother) new lisp where we'll be using brackets for forms and lists and no parenthesis in sight. It's a wild theory.

Re: CSS now has an if() conditional function

#227
post #196

Earlier quoted context omitted.

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.

The big performance sink in CSS is rule matching, or layout if you consider that to be part of CSS.

Efficient evaluation of expressions is a solved problem.

Having conditionals would actually improve performance because you can use fewer rules.

Re: CSS now has an if() conditional function

#228

Earlier quoted context omitted.

But then why was it added?

Because it's silly to rely on hard to read hacks when you could just add an if() function.

Yup. It's the same reason nested CSS was added. It doesn't really add any new functionality. Just makes your CSS neater (or way messier when misused). it's syntactic sugar really

Re: CSS now has an if() conditional function

#229
post #200

Earlier quoted context omitted.

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.

You can do without javascript. Checkbox `:checked` + `label` trick for toggling states still works. See: https://codepen.io/abdus/pen/bNpQqXv

Thanks, I’ll check this out!

Re: CSS now has an if() conditional function

#230

Earlier quoted context omitted.

My crackpot theory is that what stops newcomers is how unergonomic "(" and ")" are to type on typical keyboards. If mainstream lisp dialects used square brackets instead, we'd all be programming in it!

> If mainstream lisp dialects used square brackets instead, we'd all be programming in it! You've almost convinced/nerd-sniped me to write a(nother) new lisp where we'll be using brackets for forms and lists and no parenthesis in sight. It's a wild theory.

It's just a reader macro, parse out quotes, other reader macros, then replace [ -> (, ] -> ) in the rest and throw into (read).
Post reply on HN