Skip to main content
6 events
when toggle format what by license comment
Aug 17, 2021 at 9:50 comment added Konrad Rudolph @slepax It’s an established pattern in C#. Yes, there are better modern solutions but the API pattern is from a time before C# supported those. To stay consistent with those APIs, the pattern persists, and it’s best practice to follow it. At any rate the pattern really isn’t error-prone at all, just unnecessarily verbose.
Aug 17, 2021 at 9:30 comment added slepax @Tacoタコスreturning a boolean result and a value makes redundant code/logic and makes the program prone to errors. If the function returns false then the returned value must be null, and if the function returns true then the returned value must not be null. Any other scenario (which can happen with the original code) is wrong and would require development time tracing the problem. I will admit that I am not familiar with a 'try pattern', is it a design pattern? Even if it is, design patterns are guidelines or skeleton structures and can/should be adapted where it makes sense.
Aug 17, 2021 at 8:16 comment added Taco Thanks for taking the time to answer, and welcome to CodeReview! The try pattern is designed to return a boolean value indicating if the attempt was successful or not. It’s great to explicitly check for null after getting the value back out, though if the method returns false, we already know the output is invalid and as such, within the scope of the use-case, we don’t use the it.
Aug 17, 2021 at 6:44 history edited slepax CC BY-SA 4.0
Incomplete answer
Aug 17, 2021 at 6:40 review First posts
Aug 17, 2021 at 12:50
Aug 17, 2021 at 6:38 history answered slepax CC BY-SA 4.0