[Proposal] Better handling of multiple comparisons with the same variable (`a > min && a < max`)
See original GitHub issueProblem
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:
- Good readability
- Performance benefit since
a
can be evaluated exactly once
Cons:
- 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:
- Alright readability
- Covers many scenarios
- Can be easily adapted for future
switch
(case 1..3:
).
Cons:
- Not clear whether the range is inclusive or exclusive
- 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 Cω.
Pros:
- Good readability
- Can be adapted for future
switch
Cons:
- 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:
- Created 9 years ago
- Reactions:2
- Comments:13 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It was mentioned on CodePlex that functionality like this could be pretty easily accomplished through the pattern matching proposals and extension methods.
e.g.:
@gafter It was mentioned in #7632. The pattern counterpart is something that one would expect.