Pick a default `non-zero` option for `explicit-length-check`
See original GitHub issueI suggest picking a default value for the non-zero
option.
not-equal
Pros:
!== 0
is the inverse of=== 0
, like “is it not empty?” and “is it empty?”!== 0
does not perform type coercion (considering that the general consensus is that implicit type coercion is bad)
Cons:
- If
array.length
isundefined
,array.length !== 0
would evaluate totrue
, which is incorrect if we are asking “is it not empty?”
greater-than
Pros:
- If
array.length
isundefined
,array.length > 0
evaluates tofalse
, which is “more correct” than the!== 0
case - (subjective) A positive question in a condition is more readable than a negative question, like
is it populated?
for> 0
vsis it not empty?
for!== 0
Cons:
- Performs type coercion (this actually might be good in this case, see pro # 1)
greater-than-or-equal
Pros:
- same as for greater-than
- same as for greater-than
Cons:
- same as for greater-than
- (unconfirmed) More mentally demanding because it actually has two conditions in one expression (
greater than 1 OR equal to 1
) - (unconfirmed) Used less often than
!== 0
or> 0
I didn’t perform a thorough analysis when I started using !== 0
in my code, and now I think that actually > 0
is a better option.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Set default values for fields or controls - Microsoft Support
This article explains how to set a default value for a table field or for a control on a form in an Access...
Read more >How to store a specific non-zero default value in a linked field?
Solved it. What one has to do is to make changes in schema. Then, go to Tools --> Update Database Structure --> go...
Read more >How to set Default value for Numeric Control on Front Panel?
I have several input values that are really configuration parameters that I want to set with non-zero Default values.
Read more >NonZeroUsize in std::num - Rust
For example, Option<NonZeroUsize> is the same size as usize : ... The default implementation is almost always sufficient, and should not be overridden ......
Read more >Float property non-zero default, is it possible? - Stack Overflow
Note that you still have to set the property to the default in TMyObj's ... it by setting the value I want as...
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
I agree. I prefer
greater-than
as default.@ryaxc Your example is not polymorphic. There are other types than
Array
that could havelength
.