SSW.CleanArchitecture
SSW.CleanArchitecture copied to clipboard
♻️ Using Result object as control flow instead of exceptions
Premise:
- Exceptions are slower than Result objects (https://youtu.be/a1ye9eGTB98 - quick benchmark shows ~1us slower)
- Using Exceptions as a control flow is a questionable approach, since it allows code to jump from nested method all the way to the caller (questionable = both good and bad)
- Using result objects everywhere means more codes to write
Consideration:
- Using mixed method is a brain overload for a small performance benefit
- We haven't seen any big performance problems yet on our clients
Proposed decision:
- Keep using exceptions for now - keep it simple
- When there's a need arise (e.g. performance requirement, validation requirement) - handle it case-by-case
TODO: @christoment write a rule + maybe CTF
Nick Chapsas has a good video on this: https://www.youtube.com/watch?v=YbuSuSpzee4
He leverages Language Extensions library: https://www.nuget.org/packages/LanguageExt.Core
Another option is Fluent.Results: https://www.nuget.org/packages/FluentResults
Closing as this is a duplicate of #137