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.

Lint suggests "not (isNull x)" over "x <> null"

See original GitHub issue

Description

The linter suggests replacing a null check (x <> null) with the more complicated not (isNull x). I’m not coming up with any cases where I think a null check would be better as not (isNull x).

image

Repro steps

Please provide the steps required to reproduce the problem

  1. Add a <> null check to your F# code

  2. View linter error

Expected behavior

The linter doesn’t warn on <> null checks.

Actual behavior

The linter warns on <> null checks.

Known workarounds

Disable the linter.

Related information

  • Operating system
  • Branch
  • .NET Runtime, CoreCLR or Mono Version
  • Performance information, links to performance testing scripts

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
asikcommented, Aug 18, 2021

Null checks are difficult. And not using <> null is a good suggestion: https://latkin.org/blog/2015/05/18/null-checking-considerations-in-f-its-harder-than-you-think/

I wonder if this is still true today. Lots of work went into optimization in both F# and the JIT since then. I tried it quickly on SharpLab (link) and the generated code was properly inlined.

Well, nevermind, it`s still bad.

1reaction
jgardellacommented, Jun 8, 2020

@abelbraaksma Yes it is, but we changed from using attributes to using comments for that. But you cannot disable a specific hint, you can only disable all Hints. In this case you could add something like // fsharplint:disable Hints.

I had suggested removing the hint from the config itself as then you can disable just that hint, and it sounded like that’s what was wanted. But I agree with you that this is useful hint and probably best to keep it on by default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Open up isNotNull, adding it to the top-level functions for ...
Linter currently suggests use of isNull when it sees x == null or x <> null , which leads to debate in the...
Read more >
Why does NULL = NULL evaluate to false in SQL server
The expression "NULL = NULL" evaluates to NULL, but is actually invalid in SQL; yet ORDER BY treats NULLs as equal (whatever they...
Read more >
ISNULL vs IS NULL performance
Hello all,. I have a question on what the major differences for performance between using. WHERE field IS NULL. vs. WHERE ISNULL(field,0) =0....
Read more >
Understanding null safety
Null safety eliminates that problem at the root by changing the type hierarchy. The Null type still exists, but it's no longer a...
Read more >
IsNull function (Visual Basic for Applications) - VBA
Returns a Boolean value that indicates whether an expression contains no valid data (Null). Syntax. IsNull(expression). The required expression ...
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