Avoid usage of Rec.Count() if possible #722
Replies: 2 comments
-
@christophstuber, this idea was long overdue where I've today decided to create the rule for this. I've ended up splitsing this into two separate rules. The reason for this, is that I believe the first one (LC0081) could be set as a warning for all projects, where the second one (LC0082) is a balance between performance and readability of the code. In this way it's more flexible on which of these rules want to be enforced.
Which both is now available in the v0.31.4 (pre)release version of the LinterCop. Thank you for creating this idea, especially the part on the Rec.Find('-') with Rec.Next(), that is a nice catch. |
Beta Was this translation helpful? Give feedback.
-
The rules are now available from the release version v0.32.0 of the LinterCop. |
Beta Was this translation helpful? Give feedback.
-
Count can be one of the most expensive database operations on large tables. I often see examples like this in code:
Checking for no records:
Should be replaced by:
Checking for any records:
Becomes:
Checking for exactly one record:
Refering to https://vjeko.com/2017/03/08/the-if-count-1-conundrum/
Checking for more than one record:
Beta Was this translation helpful? Give feedback.
All reactions