Skip to content

Commit

Permalink
Updated AV1570 (dennisdoomen#114)
Browse files Browse the repository at this point in the history
* Removed AV1570

because it advocates outdated language usage.

* Review feedback
  • Loading branch information
bkoelman authored and mapfel committed Mar 22, 2021
1 parent d1c0010 commit 610c024
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Src/Cheatsheet/Cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ NOTE: Requires Markdown Extra. See http://michelf.ca/projects/php-markdown/extra
* Don’t allow methods and constructors with more than three parameters (AV1561)
* Don’t use `ref` or `out` parameters (AV1562)
* Avoid methods that take a `bool` flag (AV1564)
* Always check the result of an `as` operation (AV1570)
* Prefer `is` patterns over `as` operations (AV1570)
* Don’t comment-out code (AV1575)

<br/>
Expand Down
17 changes: 15 additions & 2 deletions Src/Guidelines/1500_MaintainabilityGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,21 @@ Often, a method taking such a flag is doing more than one thing and needs to be
### <a name="av1568"></a> Don't use parameters as temporary variables (AV1568) ![](images/3.png)
Never use a parameter as a convenient variable for storing temporary state. Even though the type of your temporary variable may be the same, the name usually does not reflect the purpose of the temporary variable.

### <a name="av1570"></a> Always check the result of an `as` operation (AV1570) ![](images/1.png)
If you use `as` to obtain a certain interface reference from an object, always ensure that this operation does not return `null`. Failure to do so may cause a `NullReferenceException` at a much later stage if the object did not implement that interface.
### <a name="av1570"></a> Prefer `is` patterns over `as` operations (AV1570) ![](images/1.png)

If you use 'as' to safely upcast an interface reference to a certain type, always verify that the operation does not return `null`. Failure to do so may cause a `NullReferenceException` at a later stage if the object did not implement that interface.
Pattern matching syntax prevents this and improves readability. For example, instead of:

var remoteUser = user as RemoteUser;
if (remoteUser != null)
{
}

write:

if (user is RemoteUser remoteUser)
{
}

### <a name="av1575"></a> Don't comment out code (AV1575) ![](images/1.png)
Never check in code that is commented out. Instead, use a work item tracking system to keep track of some work to be done. Nobody knows what to do when they encounter a block of commented-out code. Was it temporarily disabled for testing purposes? Was it copied as an example? Should I delete it?

0 comments on commit 610c024

Please sign in to comment.