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.

[Proposal] Better handling of multiple comparisons with the same variable (`a > min && a < max`)

See original GitHub issue

Problem

Consider these very common code patterns:

if (a > min && a < max) ...
if (value == Enum.Value1 || value === Enum.Value2) ...

I think it is worth considering how verbosity here can be reduced – especially since it could also give a performance benefit for cases like

if (Slow() > min && Slow() < max) ...

Potential solutions

A. Ternary comparisons

For <, >, >=, and <= one solution can be Python-like min < a < max.

Pros:
  1. Good readability
  2. Performance benefit since a can be evaluated exactly once
Cons:
  1. Does not handle a == x || a == y.
B. Range comparisons

Example:

if (a in (min...max)) ...
if (value in (Enum.Value1, Enum.Value2)) ...
if (x in (1,2,3..7)) ...
Pros:
  1. Alright readability
  2. Covers many scenarios
  3. Can be easily adapted for future switch (case 1..3:).
Cons:
  1. Not clear whether the range is inclusive or exclusive
  2. Too much new syntax for a simple case?
C. Quantum superpositions

Example:

if (value == any(Enum.Value1, Enum.Value2)) ...

This is similar to Perl’s Quantum Superpositions and something that was already implemented in Microsoft Research’s .

Pros:
  1. Good readability
  2. Can be adapted for future switch
Cons:
  1. In practice only covers equality (x > any(1,2) is possible, but useless in most scenarios). Could be combined with solution A for a limited comparison support.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
HaloFourcommented, Jan 29, 2015

It was mentioned on CodePlex that functionality like this could be pretty easily accomplished through the pattern matching proposals and extension methods.

e.g.:

using static Some.Namespace.RangePatternMatcher;

if (x is between(5, 10)) { } // range comparison
if (x is any(1, 2, 3, 4, 10)) { } // set comparison
0reactions
alrzcommented, Aug 15, 2016

@gafter It was mentioned in #7632. The pattern counterpart is something that one would expect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A general introduction to adjustment for multiple comparisons
Therefore, there are two ways for adjusting the statistical inference of multiple comparisons. First, it could directly adjust the observed P ...
Read more >
Methods to adjust for multiple comparisons in the analysis and ...
Some studies have compared a selection of methods which adjust p-values to account for multiplicity to handle multiple outcomes in trials.
Read more >
False Discovery Rate
When we are conducting multiple comparisons (I will call each test a “feature”), we have an increased probability of false positives. The more...
Read more >
Multiple Comparisons Emphasizing Selected Contrasts
pairwise comparisons symmetrically but favors and emphasizes them relative to more com- plex contrasts. In many experimental situations, some subset of ...
Read more >
Appendix B: Introduction to Multiple Testing
This appendix introduces the hypothesis testing framework for this report, the multiple testing problem, statistical methods to adjust for multiplicity, ...
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