question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle Maths

See original GitHub issue
  1. We decided on strict maths going forward but there is general unease about forcing () around every calculation
  2. I don’t think we want to change things massively or go back to the drawing board

See #1872

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).

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:102 (87 by maintainers)

github_iconTop GitHub Comments

3reactions
thanycommented, Feb 2, 2018

@matthew-dean Incidentally, this is how Sass resolves the problem, illustrated by this example:

That’s a brilliant solution without resorting to a different operator. If the expression is possibly valid CSS, leave it.

Personally, I think making developers try to remember in which cases math will occur based on the existence of magic expressions is kind of crazy-making

Disagree. It’s a simple set of rules, no different from any other sets of (crazy or not) rules you need to remember.

There are a few edge-cases where maths does occur without meaning to, but then you’ll just apply parentheses and you’re done.

3reactions
matthew-deancommented, Oct 31, 2016

To simplify / restate the proposal - Math changes would be as follows

  1. Addition and subtraction would only be calculated on like units. e.g. 1px + 2px = 3px, 1px + 1vh = 1px + 1vh
  2. Division and multiplication would only be calculated with unit-less divisors/multipliers. e.g. 10px/2 = 5px, 10px/5px = 10px/5px
  3. Value ratios without units would be treated similarly to # 2. e.g. 1/3 = 1/3
  4. For simplification, expressions with partially invalid sub-expressions can be treated as an invalid math expression and output as-is. e.g. 1px + 2vh / 2 = 1px + 2vh / 2

This proposal solves the following (from this thread):

  • font: 10px/5px and similar (ratio) syntax (no calculation)
  • calc(100vh - 30px) (no calculation)
  • lost-column: 1/3 and similar custom ratio syntax (no calculation)

At the same time, these changes would preserve 99% of typical Less math usage. As well, the existing unit() and convert() functions allow users to cast values into compatible units for math.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Learn Math Fast: Smart Study Tips for Students
1. Use real-world, concrete examples ... Math solutions can be very abstract, which makes them difficult to remember and understand. One of the ......
Read more >
14 Ways to Study Math - wikiHow
1. Work through extra practice problems, as well. Your teacher assigns a certain number of problems for homework, but if you don’t feel...
Read more >
6 Ways to Help Students Understand Math - Edutopia
1. Create an effective class opener. · 2. Introduce topics using multiple representations. · 3. Solve the problems many ways. · 4. Show...
Read more >
How to Study Math in College | Department of Mathematics
Homework · Get the assignment accurately off the blackboard. · Follow the directions. · Work neatly and accurately. · Show your complete work,...
Read more >
6 Effective Tips to Study Maths - Jagran Josh
Practice as much as you can. Maths is a hands on subject. · Start by solving examples. Don't start by solving complex problems....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found