-
I just recently learned about this library and like how it cleans up as well as clarifies the code. One thing that I am wondering about is the reason to explicitly return the input from the Guard clause. I guess it could be beneficial in some cases, but the way in which I saw the library being used and the way in which I am using it there is no need for it and it actually causes VS2019 to complain that I have an unnecessary expression value (IDE0058). Example code:
The solution to remove the VS nag is to actually write this code using the discard variable, but then I feel like I am losing the benefit of the cleanliness of these clauses.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In constructors most of the time you're doing some check and then assigning the input to a field. Guards get used in constructors a lot - it's a primary use case. So going from
to this:
is a big win. I can see how it could cause some annoyance in your methods, though. Using a discard is probably your best bet. |
Beta Was this translation helpful? Give feedback.
In constructors most of the time you're doing some check and then assigning the input to a field. Guards get used in constructors a lot - it's a primary use case. So going from
to this:
is a big win.
I can see how it could cause some annoyance in your methods, though. Using a discard is probably yo…