-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-conditional-4] Rename @when to @if #6684
Comments
My observation is that I think it is important to recognize that CSS is a not a general purpose language. It is a domain-specific language. An essential part of a domain specific language is keeping the domain of the language in mind when making keyword and syntax decisions. I'd also argue that when a language uses a different-from-the-familiar keyword, that can signal to a engineer that the keyword may not operate with the same sense or nuance that it does in another language. This could be particularly valuable in a language like CSS, where its nature is very different from general purpose languages.
That may be the reasoning of the folks that selected
I'd say most languages have such artifacts -- where the needs of the community of the time required the language to have a given feature. It's the reality of working on something while it is in use. Compromises have to be made to maintain compatibility with the users of a tool/language/technology. And I'd say it's misleading to call using @when as a reason to call CSS weird. Again, CSS is not a general purpose language. It has needs that general purpose languages do not, so naturally it will differ from general purpose languages. That's the whole point of creating a domain specific language.
This is a valid claim, as far as it goes. However, it focuses on the "quantity of those affected" without accounting for the "degree of impact". The impact of using
Just because it was done before doesn't make it the best thing in every scenario or language. It may not have even been the best thing at the time, just happened to be what someone thought of. Hopper's comment on this fallacy is probably the best: "The most dangerous phrase in the language is, ‘We’ve always done it this way.’" I'm also curious what the actual statistics are around the 'if' keyword, and the connections between those languages that use it. I suspect we'll find a common set of ancestors (or ancestor) there. :)
That's the future's problem. One can "what if" any idea into oblivion or stagnation.
Is CSS synchronous? I'd say it is more existential. It either is applied or is not. There's not, in some senses, a sequence to CSS. In natural language, when does have "when this becomes true, ...". That also applies to if -- "if this becomes true, ...". That it is not its only nuance. If we were talking tenses, it can also apply to "present perfect" in addition to the "future" tense you're referring to. For instance, the sentence "when I read, I wear funny hats" both captures past, present, and future conditions. And only future because we're assuming my past and present behavior is predictive of future behavior. That nuance of when applies to CSS quite well. "When my page is 900px wide, all text will be green" is a similar nuance as "when I read, I wear funny hats".
We still type???? ;) My guess it'll be typed once or twice, predictive text generated hundreds of times, and cut-and-pasted thousands of times. Again, CSS is its own domain. I think the context shift is sufficient to flip the switch in the brain from @if to @when. The arguments for and against don't feel compelling to me in either direction. The concerns about backward compatibility are valid but there are also times when one has to let an API change to accommodate future changes. Following common patterns has value but there are times when we have to adopt a new pattern -- otherwise we're stuck doing the same thing over and over, forever. Natural language and conveying intent is complicated to evaluate -- natural languages are richly varied and highly complex, while a programming language is, by design, specific (to their domain of machine instructions) and unambiguous. And domain languages are, by design, even more specific to their domain, Making nuanced decisions about keywords of a language on that basis is difficult and fraught with cultural bias. :) |
Since this thread leads with that, I'll re-iterate my thoughts from elsewhere:
I know some have expressed that |
CSS should actively steer clear of familiar control flow structure syntax because it is not an imperative language. "If this is true do this thing" vs "When this is true use these rules" So a vote here from me for |
There are many ways to misunderstand any programming structure once we start fleshing it out into natural language according to our own preconceived notions. You are adding "will be", but it could just as easily be (theoretically) understood as "When my page was 900px wide, all text should have been green". I mean, unlikely that anyone would actually think that, but also unlikely that they would have difficulty understanding what |
Control flow is not a characteristic of imperative languages. Many (possibly most) declarative languages have control flow structures, and as I mentioned in my original post, tend to call conditionals
|
I'm leaning towards First of all, I want to talk about the difference in meaning between the words "if" and "when". I'm not a native English speaker, so I may get nuances wrong, but I think people generally agree that "when" implies some timescale, a moment in the future when a certain condition will inevitably happen. I can say "I don't know when I'll leave the house" and "I don't know if I'd leave the house" and they'd mean different things; the first implies I will leave the house, I'm just unsure at what point in time. The second implies I'm not sure whether I'll leave the house altogether, regardless of time. For this CSS condition, I don't believe it would make sense to use As for the clash with SASS, that's the bigger issue. I think most people want to call this rule First, I want to address arguments along the lines of "we're bending some JavaScript features in order to not break the web, why can't we do the same for CSS". Yes, we did have to rename some things for JavaScript just because the initially proposed name would break things. In my opinion, this is a bit different. Let's say (hypothetically) I built a site 5 years ago using MooTools (specifically using Now, let's say I wrote a preprocessor that would clash with a new CSS feature, just like SCSS. Would I expect CSS to go out of its way to avoid doing so? No, definitely not, as the amount of users affected by my preprocessor breaking would likely be insignificant. Obviously, the difference with SCSS is that it has an absolutely massive user base. Many people would be negatively impacted by a change that would cause their SCSS to break, cause them to have to migrate or stick to an older SCSS version that prevents them from getting other juicy updates to SCSS. The question is whether or not we should take this into consideration. Is SCSS "part of the web ecosystem", and we therefore have to protect them from this type of inconvenience, or is SCSS just a third party tool that shouldn't be taken into consideration whatsoever when making decisions about CSS? This is (the way I see it, anyway) at the heart of this discussion, and it's a difficult question. I wholeheartedly believe in making the web an amazing place for everyone, and breaking SCSS In the end, if we can get away with introducing |
@vrugtehagel @LeaVerou well reasoned. @vrugtehagel you made me think though, wouldn't |
👍
👍 |
A comment in another thread mentioned:
Please take a look at the following code: @when supports(display: grid) {
} @else {
} The |
Maybe it's because English is not my first language, but I am failing to see the above argument. Why |
@mikemai2awesome Sorry for not being clear. I meant to say |
I learned at school (as a non-native English speaker) that "when" can be both "if" and "as soon as". So, Though that's just my opinion, like others here expressed their opinion. To make a proper decision, it might be good to get some statistics of what people would prefer. That should be done without biasing them to one or the other side by the question. Sebastian |
No strong opinion, but at the very least this is wrong:
The word "when" does not imply timing per se, the sentence (+tense) does.
I think this is a stronger point. As a rule of thumb though, I don't like |
FWIW in most other reactive programming languages, which by definition share this trait, conditionals are still called |
I think you are making the point that But it doesn't mean that As I saw other people ask for examples of why /* when it's sunny, sunglasses are visible but umbrellas are hidden */
@when <it's sunny> {
.sunglasses { visibility: visible; }
.umbrella { visibility: hidden; }
}
/* when it's overcast, both umbrellas and sunglasses are hidden */
@when <it's overcast> {
.umbrella, .sunglasses { visibility: hidden; }
}
/* when it's raining, umbrellas are visible, but sunglasses are hidden */
@when <it's raining> {
.umbrella { visibility: visible; }
.sunglasses { visibility: hidden; }
} This is my mental model of media queries (as in how I "read" them in my mind). Now I understand that other models are possible. It's not impossible to read these sentences with |
Btw, this was implicit, but to write it out: I agree with the argument we shouldn't care too much about SASS. In case it's a wash, not breaking tooling should win though, for the convenience of people using these tools. |
Do you mean when there is a clear majority? 🤪 ^ Tongue in cheek, but I do think that highlights another problem with when: in natural language, using "when" implies certainty that something will happen, and only potential uncertainty as to its timing. However, in this case we don't want to imply any such certainty, as these queries may never match. |
I'm not a Sass expert, but you may be correct. Less does this with several functions that were added to CSS that already existed in Less, or which cannot be evaluated at compile-time (sometimes because of For example, this input for Less: @my-color: #333;
.box {
value-1: rgba(var(--my-color), 0.5);
value-2: rgba(@my-color, 0.5);
} ...will produce this output... .box {
value-1: rgba(var(--my-color), 0.5);
value-2: rgba(51, 51, 51, 0.5);
} The downside is that the compiler can't really "validate" what's passed through (although, in general, a CSS pre-processor probably should allow invalid syntax to pass through, for various spec reasons). In other words, a Less author may have been intending to write a valid Less function, and for those special-case functions, Less will not throw an error and will instead output as-is (if a parsing / evaluation error is present). AFAIK, Sass took a different approach of name-spacing Sass functions, and asking people to re-write existing code (I think?). But yes, in the case of I think another reasonable proposal mentioned above is just to alias |
@rviscomi I presume there's a limitation where you can't test pages that don't have an explicit sourcemap linking back to an SCSS file, yet even without that, 0.8% seems pretty significant. 😬 This sort of reminds me of #SmooshGate, with the obvious difference that shipping |
I’ve wondered this myself. As far as I can tell, Sass syntax is |
@meyerweb In the list shared above by @rviscomi most entries indeed perform a check involving a Sass variable (e.g. |
@matthew-dean that's right, we're limited by the sites that choose to provide the source mapping. We also only look at stylesheets with |
@romainmenke wrote:
That was initially pointed out by me and later picked up by @nex3 as one possible solution with some restrictions.
That's incorrect. E.g. Having said that, there are no sites using the Though according to its documentation Sass allows any core library or user-defined function as expression within This means that in order to let Sass' Sebastian |
This is a slippery slope. By the same token, both Less and PostCSS allow you to also define an So you end up with something like this PostCSS plugin, which has about 10,000 downloads per week. In other words, in some sense it's good this discussion is happening, because it's clear that CSS and CSS tooling need a different approach to expanding syntax, and I think it's good that authors (and thought leaders) of CSS are taking this problem seriously. |
@romainmenke wrote:
@SebastianZ wrote:
I missed that. @if media(screen) and $light-theme {
background-color: $light-background;
color: $light-text;
} I now also realise that keeping both sass List of function names from the conditionals posted above : https://gist.github.com/romainmenke/4cd042c331031538a441c2adf76a5c42 List of function names with functions with vendor prefixes or
|
I write sass every day, and I would honestly take the hit of doing a search and replace once to get a syntax for the next decades that's more commonly accepted in programming languages (not just imperative ones) to the point that even the CSSWG minutes reference it as if/else, and it's also a lot easier to understand for non-native speakers. Choosing Even wikipedia doesn't even bother talking about other constructs. |
It's a fair point. I suppose there's a fair amount of assumption that the keywords would need to co-exist, and that there's inherent conflict. But... there actually wouldn't be in practice. 🤔 Because both usages would not happen immediately for the same stylesheet author. It could be like:
Basically, it wouldn't break builds. Existing files w/ existing Sass dependencies would continue to compile just fine. It's just when a Sass user wanted to use a native Basically, it doesn't break live code, because there's not an external compiler you don't control, and it doesn't break builds, because languages / existing files are inherently tied to a fixed compiler version. It's more like a "future compatibility question". So I wonder if people have been thinking about this in the wrong way. If browsers added I'm just spitballing, I'm not sure it's the best choice, but just to point out that choosing |
Given that that's precisely what you would want to do the moment you started using the CSS @if, it would be a problem immediately for such a person. This isn't a small side issue, it's the core problem that will immediately manifest for every such user. |
Not as long as the preprocessor provides a way to output native CSS constructs explicitly. As said multiple times, this could be done via a prefixed rule like |
That's been addressed multiple times already. |
That, without specifics, may mean anything. |
I invite you to read the preceding comments in the thread that addressed the exact subject of your comment. |
In practice, how? Would we not assume that if there were a conflict, Sass would have a version that addressed it before a user could reach for it? i.e. I can't envision a scenario where CSSWG picked Again, there's an argument (that I've also made) that So, again, I like |
I appreciate the discussion, and wanted to share that I am not opposed to either I am softly, less in favor of When I’m writing JavaScript or any scripting language with Example 1: the if (is_truthy) doThis() Example 2: the const runThis = () => {
if (is_truthy) doThis()
} In either example, I do not expect This is the reason I am softly, less in favor of I want to briefly share how I positively map CSS conditionals to concepts in JS. I mentally map them to listeners, observables, and callbacks. matchMedia('(min-width: 600px)').onchange = doThis;
matchMedia('(min-width: 600px)').addEventListener('change', doThis);
new ResizeObserver(doThis);
class extends HTMLElement {
connectedCallback() {
doThis(this);
}
} A term like I’d survive if it were called |
@jonathantneal I actually quite like |
We could go math-formal and name it |
This is a good way to articulate it. A counter-point is that a declarative language like XSLT has <xsl:choose>
<xsl:when test="number($foo) mod 2 = 0">Even<xsl:when>
<xsl:otherwise>Odd<xsl:otherwise>
<xsl:choose> Interestingly, @meyerweb |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Thanks @tabatkins. Sorry @cferdinandi and everyone, that was a copy paste from Stack Overflow as an XSLT example; I didn't consider the content. |
@matthew-dean All good! I didn't think you meant anything malicious by it! |
Let's not overthink this - use |
Time goes by, and Sass could start to use some other prefix for their custom rules. For example, |
The reasoning for using
@when
over@if
is that@if
clashes with Sass, a widely used CSS preprocessor. To my knowledge, no other reasoning exists for this decision.However, there is a lot of pushback against this decision (and general philosophy) in #112. I have gathered quotes about this below.
Some arguments against
@if
have been posted by Sass maintainers in w3ctag/design-principles#335 which has received a lot of attention from the Sass community through this tweet.My take:
@when
keyword decades after Sass is not used any more, making for yet another funny story about "why CSS is weird". The whole point of preprocessors should be to prototype features for CSS' future. Designing CSS around Sass is going the wrong way up the proper chain of dependency. It's like Babel forcing TC39 to not change a proposal because too many people transpile it a certain way.if
for conditionals in almost every language that includes conditional statements (and not just imperative languages as has been erroneously mentioned). For example, spreadsheets and all flavors of SQL (SQL Server, MySQL, even SQLite), Lisp, Haskell, Erlang, XSLT, all of which are considered declarative.@each
,@for
,@while
are all taken. How much do we contort CSS to avoid clashing with preprocessors?@when
has serious usability problems:if
is more synchronous.when()
as well? Are we going to name them something unrelated, likecond()
? Do note that these also clash with Sass if calledif()
... link@when
is adopted, this will make for decades of users mistyping CSS conditionals.Quotes from [mediaqueries][css-conditional] else #112:
@Marat-Tanalin (1):
@Marat-Tanalin (2):
@upsuper:
@bradkemper:
@leaverou:
@svgeesus:
The text was updated successfully, but these errors were encountered: