Re: [csswg-drafts] [css-values]: Express conditional values in a more terse way (#5009)

So... having had this conversation, including CSSWG and several follow on conversations I would like to revise my take from yesterday since my examples included a vector in the MQ to provide the context and I understand this better from several angles now...

Thinking about the two things being interchangeably referred to as `switch()` together is definitely useful.  Seeing this case and the comments means that @javifernandez and I will continue to think about whether something like this could work - I can't see any reason it couldn't

```
@media not (prefers-color-scheme: dark) and not (prefers-contrast: low) {
  :root { --c: 1; } // light, high-contrast
}
@media not (prefers-color-scheme: dark) and (prefers-contrast: low) {
  :root { --c: 2; } // light, low-contrast
}
details.note > summary {
 display: block;
 color: switch(
                      (--c == 1) hsl(120, 70%, 30%); 
                      (--c == 2) hsl(120, 70%, 30%); 
                     default hsl(120, 70%, 30%); 
 }
}
```

I believe that is useful and super-powerful, but I also agree that if you have _exactly_ this case (not uncommon) and not some more complex expression, that is unnecessarily verbose and inherently more complex.  So, I think there's a lot of value (separately) to the 'index based' function that I agree with @tabatkins is actually different from an authors perspective and maybe from an implementation one too.  Unfortunately with kind of a lot of thought I don't see any way they can both be called `switch()` and if they were it would be unnecessarily complex - I guess that's why we have things like `if` and `switch` in languages which do kind of similar things in different ways... I think here too both are valuable.

I think you could make a compelling argument for either of them to be called 'switch' tbh, but I not-entirely-mildly prefer to keep my thing called switch as I lean toward 'it is slightly more switch-like in ways that matter to me' and, to a lesser extent because it's been circulating and I feel like delivering something else called that now will add confusion.

@emilio seemed to imply he wasn't attached to the name, a quick straw poll of people thought that this seemed rather like `if()`, but idk... can we at least agree that they do different things and continuing to call both `switch()` seems bad?  `case()`?  `index-switch()`?  something else? 



-- 
GitHub Notification of comment by bkardell
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5009#issuecomment-626029010 using your GitHub account

Received on Friday, 8 May 2020 21:28:21 UTC