You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Possibility to add another case for calc which like font, with strict mode off, essentially turns strict mode on for a rule ? Too many exceptions in the future?
@seven-phases-max :
Well, there're a lot of other possibilities, e.g. ./ or require parens for division (e.g. 1/2->1/2 but (1/2)->0.5) etc...
Also, the "special cases" (e.g. properties where x/y can appear as shorthand) are not so rare (starting at padding/margin and ending with background/border-radius and eventually there can be more) so we just can't hardcode them all like it's done for font (and because of that I think that the current font "workaround" is just a temporary and quite dirty kludge that ideally should be removed too).
I don't think we want to change things massively or go back to the drawing board
Yes, I suggested to start this only because if we want some "default" strict math in 3.0 we'll have to invent something less heavy than the current one (and a possibility of fixing all the problems without introducing any new --alt-strict-math option seems to be quite unreal because of hidden issues behind the font-like hardcoding solution...).
I think at the moment I am in favour of initially expanding strictMaths to be
Off
Division
On
and then for 2.0.0 setting the default to be Division
So..
Media Queries - if off, switch to division for sub nodes
Font - if off, switch to division for sub node
calc( - if off or division, switch to on for sub nodes
This will fix calc but won't fix #1627 and related stuff.
I mean yes, calc(100% - 10 px) => unchanged could be a solution for the calc but this does not cancel the need for a less-heavy-than-parens-everywhere solution.
If strict maths is being revisited, I'd like to suggest that Less functions like percentage() not require extra parentheses inside them. With strict maths on, you have to double-wrap the argument. This would greatly reduce the possibility of confusion and tough-to-find bugs, since both percentage(16 / 17) and percentage((16 / 17)) would be valid.
@calvinjuarezV2 provides a plugin subsystem where a plugin can add an arbitrary number of functions to the environment and in this sense the core won't be able to decide if such built-in function expects a single value or an expression, i.e. it is allowed to accept 16/17, and then evaluating 16/17before it is passed to a function would be incorrect (well, roughly speaking - it's a bit more complicated than that internally).
In that context ./ change seems to be my favourite though I understand it would be very dramatic change (if compared to (/), not counting it is also requires a whitespace before ., e.g. 16 ./17 and not 16./17, hmm).
I think at the moment I am in favour of initially expanding strictMaths to be
Off
Division
On
and then for 2.0.0 setting the default to be Division
Sorry I didn't respond to this before 2.0 was released. I think that's a good instinct. Naked division operators simply conflict with too much of CSS, and will conflict more and more as people use more CSS3 features. And I understand people's pushback to not require parens for all math, since it's not needed in many cases.
it is allowed to accept 16/17, and then evaluating 16/17 before it is passed to a function would be incorrect
Strictly speaking, yes that's absolutely correct. This should not be evaluated BEFORE it reaches the function, especially for a custom one. However, I think it would be smart to allow functions to opt to process arguments like this, if it makes sense. So, percentage would receive 16/17 as a text argument, and then the percentage function could make a call to some helper function to see if the text is math. In the case of percentage, the argument is not ambiguous. A CSS3 declaration is not valid here. So, other user-defined functions could operate the same way: opt to evaluate arguments for valid math equations. Therefore, it's not necessarily true that strict math "forces" a double parentheses in this case. I think to suggest that causes some pushback on the idea of strict math, that it must, as a necessity, be verbose in all cases.
However, I think it would be smart to allow functions to opt to process arguments like this, if it makes sense.
They are allowed already (just test how percentage(16 / 17) and percentage((16 / 17)) work with --strict-math=on).
Though none of functions uses:
and then the percentage function could make a call to some helper function to see if the text is math.
simply because this way each function would have to have those ~20 extra lines of that extra-helpers-conversion-arg-checking-smart-arg-handling-stuff while the own function code is just one(!) line in most cases.
Each function has to have 20 extra lines? How do you figure?
If percentage already works with single parentheses strict math on, then I don't understand @calvinjuarez's issue. You seemed to imply in your response that single parentheses was not achievable.
@matthew-dean
Essentially change the division operator in Less. Leading contender in the thread has been ./, which works but is a little strange to look at. \ is an unknown at this point without research [...] @thany, if you or someone else is a fan of this, then this is the work required. The last thing we want is just to move the breaks somewhere else.
Not at all actually. I suggested the \ operator as a last resort after not getting through, trying to get LESS to do only its own maths. If a new division operator is what it takes... Well, calc() can also do addition, subtraction, and multiplication. New operators for those? I think it's impractical. A new division operator might be a solution for things like font, background, and border-radius, but it's no solution for CSS maths.
I still think the real solution is for LESS to know about context. It should (yes, here I go again with my "should", what other word must I use?...) know that calc() is a CSS function and it should only evaluate maths that CSS can't do. But floor() doesn't exist in CSS, so that one it would have to evaluate (entirely) as to not spew out invalid CSS. I think this is mentioned before though, in different wording.
I still think the real solution is for LESS to know about context. It should (yes, here I go again with my "should", what other word must I use?...) know that calc() is a CSS function and it should only evaluate maths that CSS can't do. But floor() doesn't exist in CSS, so that one it would have to evaluate (entirely) as to not spew out invalid CSS. I think this is mentioned before though, in different wording.
Fair enough re: \, but as far as context, based on your other posts, I can guarantee it's a far more complex problem than you're thinking that it is. You really have to boil it down to:
12px/10px// Is this division, or not?10px/1.5// is this division, or not?
If you want to definitely leave / as a division operator, to mimic calc(), and not have it be ambiguous, then you absolutely need to make sure that the / is in parentheses (other than the calc() exception). That would provide predictable context.
That suggestion at the beginning of this thread is also still a possibility, and had some strong support. Essentially, that the default setting be that all math is supported outside parentheses EXCEPT division (and again, except calc(), is is now the case from 3.0+). Maybe that is the way to go. That would allow:
font: 10px/1.5; // not divisionfont: (10px/10); // division, result is 1pxfont: 10px+15px/1.5; // addition but not division, result is 25px/1.5font: (10px+15px/1.5); // result is 20px
Thing is, the result for 10px+15px/1.5 might still be hard for devs to grok, with an expression that seems to get "half-evaluated" unless it's in parentheses. If we had gone ahead and turned strict math on by default, it probably would have been fine. It's even less ambiguous. [shrug] Either way, wrapping math in some kind of context IS the way to eliminate ambiguity, and the only way for division other than changing the division operator.
The community has to essentially decide the direction. There are viable options in this thread. Each has downsides. Each has pain points. None will have full consensus. But IMO any of them are better than the current scenario. Just gotta swallow that pill.
So in an effort to work the impossible, I'd like to propose we do this (referring back to comments from 3 years ago.)
Give --strict-math 3 settings
off
division
strict (alias on for back-compat)
To settle the debate, allow the --strict-math=division switch to do the following:
Do not perform division with just / character outside of parentheses. E.g. border-radius: 55px / 25px; --> no-math (yes, that's valid CSS)
Allow division with two different methods:
a. . prefix -border-radius: 55px ./ 25px;
b. parentheses - border-radius: (55px / 25px);
Both forms are valid in parentheses - e.g. border-radius: (55px ./ 25px); would be valid
So, as a developer, if you feel one version is not your preference, you can use the other. Some may prefer not to use parentheses; some may prefer not to use a modified division operator. Something for everyone. And no more unpleasant surprises for those new to Less using what is now a widespread syntax in CSS, with the / being used in font, background, border-radius, @media queries, CSS Grid properties, and probably more in the future.
Next steps
I recommend this goes into a PR as an option, and then, as discussed, gets switched as the default for a future major version
I'm still getting a weird error one of the tests, where it it seems to turn one of the dimension nodes into an operation node (and then throws an error because it can't perform an operation on an operation node. It doesn't seem to be a parsing problem because another test not running under strictMath: division works fine. Want to check it out and see if you can help?
Activity
seven-phases-max commentedon Feb 17, 2014
Yes, I suggested to start this only because if we want some "default" strict math in 3.0 we'll have to invent something less heavy than the current one (and a possibility of fixing all the problems without introducing any new
--alt-strict-mathoption seems to be quite unreal because of hidden issues behind thefont-like hardcoding solution...).lukeapage commentedon Feb 17, 2014
I hadn't realised that its growing
https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
:(
I think at the moment I am in favour of initially expanding strictMaths to be
and then for 2.0.0 setting the default to be Division
So..
Media Queries - if off, switch to division for sub nodes
Font - if off, switch to division for sub node
calc( - if off or division, switch to on for sub nodes
seven-phases-max commentedon Feb 17, 2014
Yep, I think they are towards to allowing "shorthand values" (i.e.
x/y) in any "shorhand property"...lukeapage commentedon Feb 23, 2014
related: #1480
lukeapage commentedon Sep 5, 2014
Another option.. process calc calls but only where the units make it possible e.g
calc( 1% + 2%) => 3%
calc(100% - 10 px) => unchanged
seven-phases-max commentedon Sep 5, 2014
This will fix
calcbut won't fix #1627 and related stuff.I mean yes,
calc(100% - 10 px) => unchangedcould be a solution for thecalcbut this does not cancel the need for aless-heavy-than-parens-everywheresolution.calvinjuarez commentedon Sep 5, 2014
If strict maths is being revisited, I'd like to suggest that Less functions like
percentage()not require extra parentheses inside them. With strict maths on, you have to double-wrap the argument. This would greatly reduce the possibility of confusion and tough-to-find bugs, since bothpercentage(16 / 17)andpercentage((16 / 17))would be valid.seven-phases-max commentedon Sep 5, 2014
@calvinjuarez V2 provides a plugin subsystem where a plugin can add an arbitrary number of functions to the environment and in this sense the core won't be able to decide if such built-in function expects a single value or an expression, i.e. it is allowed to accept
16/17, and then evaluating16/17before it is passed to a function would be incorrect (well, roughly speaking - it's a bit more complicated than that internally).In that context
./change seems to be my favourite though I understand it would be very dramatic change (if compared to(/), not counting it is also requires a whitespace before., e.g.16 ./17and not16./17, hmm).ponychicken commentedon Apr 15, 2015
Another thing where less currently breaks valid css is background shorthand:
matthew-dean commentedon Apr 15, 2015
Sorry I didn't respond to this before 2.0 was released. I think that's a good instinct. Naked division operators simply conflict with too much of CSS, and will conflict more and more as people use more CSS3 features. And I understand people's pushback to not require parens for all math, since it's not needed in many cases.
@seven-phases-max
Strictly speaking, yes that's absolutely correct. This should not be evaluated BEFORE it reaches the function, especially for a custom one. However, I think it would be smart to allow functions to opt to process arguments like this, if it makes sense. So, percentage would receive 16/17 as a text argument, and then the percentage function could make a call to some helper function to see if the text is math. In the case of percentage, the argument is not ambiguous. A CSS3 declaration is not valid here. So, other user-defined functions could operate the same way: opt to evaluate arguments for valid math equations. Therefore, it's not necessarily true that strict math "forces" a double parentheses in this case. I think to suggest that causes some pushback on the idea of strict math, that it must, as a necessity, be verbose in all cases.
matthew-dean commentedon Apr 15, 2015
Our --math options could be more like:
So, we could deprecate --strict-math=true and make it an alias for --math=strict
seven-phases-max commentedon Apr 15, 2015
They are allowed already (just test how
percentage(16 / 17)andpercentage((16 / 17))work with--strict-math=on).Though none of functions uses:
simply because this way each function would have to have those ~20 extra lines of that extra-helpers-conversion-arg-checking-smart-arg-handling-stuff while the own function code is just one(!) line in most cases.
matthew-dean commentedon Apr 15, 2015
Each function has to have 20 extra lines? How do you figure?
If percentage already works with single parentheses strict math on, then I don't understand @calvinjuarez's issue. You seemed to imply in your response that single parentheses was not achievable.
84 remaining items
seven-phases-max commentedon Feb 11, 2018
Yes, so far I can't imagine any other suspicious things there.
calc() fix - fixes #974 (partially #1880)
thany commentedon Feb 11, 2018
Not at all actually. I suggested the
\operator as a last resort after not getting through, trying to get LESS to do only its own maths. If a new division operator is what it takes... Well,calc()can also do addition, subtraction, and multiplication. New operators for those? I think it's impractical. A new division operator might be a solution for things like font, background, and border-radius, but it's no solution for CSS maths.I still think the real solution is for LESS to know about context. It should (yes, here I go again with my "should", what other word must I use?...) know that
calc()is a CSS function and it should only evaluate maths that CSS can't do. Butfloor()doesn't exist in CSS, so that one it would have to evaluate (entirely) as to not spew out invalid CSS. I think this is mentioned before though, in different wording.matthew-dean commentedon Feb 11, 2018
Fair enough re:
\, but as far as context, based on your other posts, I can guarantee it's a far more complex problem than you're thinking that it is. You really have to boil it down to:If you want to definitely leave
/as a division operator, to mimiccalc(), and not have it be ambiguous, then you absolutely need to make sure that the/is in parentheses (other than thecalc()exception). That would provide predictable context.That suggestion at the beginning of this thread is also still a possibility, and had some strong support. Essentially, that the default setting be that all math is supported outside parentheses EXCEPT division (and again, except
calc(), is is now the case from 3.0+). Maybe that is the way to go. That would allow:Thing is, the result for
10px+15px/1.5might still be hard for devs to grok, with an expression that seems to get "half-evaluated" unless it's in parentheses. If we had gone ahead and turned strict math on by default, it probably would have been fine. It's even less ambiguous. [shrug] Either way, wrapping math in some kind of context IS the way to eliminate ambiguity, and the only way for division other than changing the division operator.The community has to essentially decide the direction. There are viable options in this thread. Each has downsides. Each has pain points. None will have full consensus. But IMO any of them are better than the current scenario. Just gotta swallow that pill.
matthew-dean commentedon Jun 24, 2018
Last call for a decision
So in an effort to work the impossible, I'd like to propose we do this (referring back to comments from 3 years ago.)
Give
--strict-math3 settingsonfor back-compat)To settle the debate, allow the
--strict-math=divisionswitch to do the following:/character outside of parentheses. E.g.border-radius: 55px / 25px;--> no-math (yes, that's valid CSS)a.
.prefix -border-radius: 55px ./ 25px;b. parentheses -
border-radius: (55px / 25px);border-radius: (55px ./ 25px);would be validSo, as a developer, if you feel one version is not your preference, you can use the other. Some may prefer not to use parentheses; some may prefer not to use a modified division operator. Something for everyone. And no more unpleasant surprises for those new to Less using what is now a widespread syntax in CSS, with the
/being used infont,background,border-radius,@mediaqueries, CSS Grid properties, and probably more in the future.Next steps
I recommend this goes into a PR as an option, and then, as discussed, gets switched as the default for a future major version
Fixes less#3205, partial 3.0 math regression less#1880
rjgotten commentedon Jun 24, 2018
@matthew-dean
I.e. the period acts sort of like the inverse of an escape sequence?
Not a bad idea, really...
And all things considered, probably one of the cleanest possible solutions.
matthew-dean commentedon Jun 24, 2018
@rjgotten Got a start here: https://github.com/matthew-dean/less.js/tree/strict-math-division
I'm still getting a weird error one of the tests, where it it seems to turn one of the dimension nodes into an operation node (and then throws an error because it can't perform an operation on an operation node. It doesn't seem to be a parsing problem because another test not running under
strictMath: divisionworks fine. Want to check it out and see if you can help?Fixes #3205, partial 3.0 math regression #1880 (#3228)
matthew-dean commentedon Jun 27, 2018
What I'd like to do is close this issue and create new issues that handle the remaining math questions. Specifically:
strictMath: 'division'feature.Fixes less#1880 - Adds two new math modes and deprecates strictMath
Merge pull request #3274 from matthew-dean/strict-math-division
Merge branch 'master' into feature/rewrite-urls (#3282)
Feature/rewrite urls (#3248)