Very nice video. I love your take on technical debt. Technical debt could be an etire video on its own :) I know you have a video on "When To Throw Exceptions?", still need to watch that. My take on it is to think about what the business would do. I try to give an exampel, might be a bad one though: when you give someone a warehouse address to fetch some products from there and there is no warehhouse at the address you would probably check if the address was correct. If the given products are out of stock you order new ones and ask the customers to check back later etc. These error cases are within your business domain to handle. So you handle them. In your workflow you have a happy path, but you have error pathes as well that you are prepared for or implement after it happened once. However if at the given warehouse address you see warehouse is burning than that is not within your business domain. That is an exception, since it is not expected to ever happen, it is an exceptional event, you wouldn't have an employee witht he job to handle burning warehouses.
Thank you, I use these kind of error handling, but this one is far better than what I use. Especially that map things (ok result and bad request) at controller result.
I might add some implicit converters as well to simplify returning just the error type or just the value type. // Implicit conversion from T to Result public static implicit operator Result(T value) => Success(value); // Implicit conversion from string to Result public static implicit operator Result(Error error) => Failure(error);
I generally tend to dislike the use of implicit operators because it adds a lot of "magic". As teams evolve, new devs will usually take some real chunk of time to understand what's happening. But, beyond personal preferences, this is a use case where the implicit operator could be used. I agree to that.
@@Codewrinkles I'm ok with a little bit of magic to make the code more readable in the handlers/endpoints. They just need to return the T and it will be converted accordingly.
@@Codewrinkles implicit is great here at the very least for the success case. Complaining it is magic is like complaining async methods wrap your return type in a Task for you
Very well explained. | I do agree somehow about the technical debt on adding packages to your solution, but what about implementing your own 2FA? would this also be a technical debt or we just have to reinvent the wheel?
Return a successful result without throwing an exception, and ensure that you execute code only if it is valid. For example, in the addUser function: Method A returns the user if valid, while Method B takes the user and saves it. If Method A throws an error because the user is not valid, Method B should not be called. Using a result pattern, Method A returns null, and you must test in Method B to check if the user is not null, and so on.
The way I understand it, map functions usually applies a projection to a value. I think conceptually both map and match would be a good fit. But I might be wrong.
"Why import a library for simple functionality you can write yourself in five minutes?" Clearly you're not a JavaScript programmer lol. I use something similar in all my projects.
As I mentioned in the video, source code is available for Codewrinkles members on Ambassador tier or higher. Check the link in the description to become a member and the check the Membership tab for info on how to get the source code
Felicitari pentru explicatia concisa!
Multumesc
Recently I implemented very very similar pattern and it works perfectly! I can confirm that it is awesome pattern.
Very nice video. I love your take on technical debt. Technical debt could be an etire video on its own :)
I know you have a video on "When To Throw Exceptions?", still need to watch that. My take on it is to think about what the business would do. I try to give an exampel, might be a bad one though: when you give someone a warehouse address to fetch some products from there and there is no warehhouse at the address you would probably check if the address was correct. If the given products are out of stock you order new ones and ask the customers to check back later etc. These error cases are within your business domain to handle. So you handle them. In your workflow you have a happy path, but you have error pathes as well that you are prepared for or implement after it happened once.
However if at the given warehouse address you see warehouse is burning than that is not within your business domain. That is an exception, since it is not expected to ever happen, it is an exceptional event, you wouldn't have an employee witht he job to handle burning warehouses.
I think your examples make totally sense and I agree to them. In the video you mentioned I gace conceptually similar examples, you'll see.
Excellent explainer! Already have a few places I will implement this and with that make the code easier to follow.
Glad it was helpful! And hope you are doing well. Haven't seen you on Discord for a while :)
I prefer this approach personally, my needs have been pretty basic and this would suffice
Thank you, I use these kind of error handling, but this one is far better than what I use. Especially that map things (ok result and bad request) at controller result.
Glad you found something useful in the video
Thanks a lot Dan for the awesome video
Is it better Error class to be record struct?
Well explained ❤ Thank You
Glad you liked it.
I might add some implicit converters as well to simplify returning just the error type or just the value type.
// Implicit conversion from T to Result
public static implicit operator Result(T value) => Success(value);
// Implicit conversion from string to Result
public static implicit operator Result(Error error) => Failure(error);
I generally tend to dislike the use of implicit operators because it adds a lot of "magic". As teams evolve, new devs will usually take some real chunk of time to understand what's happening. But, beyond personal preferences, this is a use case where the implicit operator could be used. I agree to that.
@@Codewrinkles I'm ok with a little bit of magic to make the code more readable in the handlers/endpoints. They just need to return the T and it will be converted accordingly.
@@Codewrinkles implicit is great here at the very least for the success case. Complaining it is magic is like complaining async methods wrap your return type in a Task for you
Excelent video my friend. Keep going
Glad you liked it. Feel free to share it with others. Thanks
How does this impact the pipelines in mediatr, when your request becomes Result instead of a non-generic type?
thank you for the video!
Very well explained. |
I do agree somehow about the technical debt on adding packages to your solution, but what about implementing your own 2FA?
would this also be a technical debt or we just have to reinvent the wheel?
Well I would probably NOT want to implement my iwn low level sms sending service. I would probably use Twilio or something.
Return a successful result without throwing an exception, and ensure that you execute code only if it is valid. For example, in the addUser function: Method A returns the user if valid, while Method B takes the user and saves it. If Method A throws an error because the user is not valid, Method B should not be called. Using a result pattern, Method A returns null, and you must test in Method B to check if the user is not null, and so on.
niiiiiiiiiiiiiice
Why are you using VS ? What about rider?
Well, I came to the conclusion that altough I like Rider much better the benefits of using it don't actually justify the monthly 16$.
@@Codewrinkles best conclusion ever
I think you are confisingn Map with Match. Map execute a mapping from the type T to the type TOut
The way I understand it, map functions usually applies a projection to a value. I think conceptually both map and match would be a good fit. But I might be wrong.
"Why import a library for simple functionality you can write yourself in five minutes?" Clearly you're not a JavaScript programmer lol. I use something similar in all my projects.
Yeah, when you add expressjs you already add around 2300 libraries :)). Unfortunately, I had to work also on Node projects in the past
code?
As I mentioned in the video, source code is available for Codewrinkles members on Ambassador tier or higher. Check the link in the description to become a member and the check the Membership tab for info on how to get the source code
@@Codewrinkles ok np