this post was submitted on 10 Aug 2024
17 points (94.7% liked)

C Sharp

1537 readers
3 users here now

A community about the C# programming language

Getting started

Useful resources

IDEs and code editors

Tools

Rules

Related communities

founded 2 years ago
MODERATORS
17
submitted 4 months ago* (last edited 4 months ago) by [email protected] to c/[email protected]
 

A collection of tools for dealing with nulls, failures and the generic type issues that arise in this domain.

https://github.com/Andy3432344/SafeResults

I'm the author, let me know what you think!

*Edit: updated to show GitHub link, sorry!

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 4 months ago (6 children)

At least for this specific example I don't know why I wouldn't use null instead of option and ?? As it's more clear what's happening as it's standard C#

Also in your example does the function to the right of | execute always?

[–] [email protected] 1 points 4 months ago (3 children)

Nulls are famously called the billion dollar mistake, and for good reason.

Option types are the answer to that problem, because they make the optionality explicit and require one to handle it or propagate it.

That being said: as someone that does functional programming professionally, this looks kinda janky, to me. But the good news is that C# is actually adding support for discriminated unions finally (seriously, it's been waaaay too damn long): https://github.com/dotnet/csharplang/blob/18a527bcc1f0bdaf542d8b9a189c50068615b439/proposals%2FTypeUnions.md

With discriminated unions, you can finally comfortably work with Option/Result types natively.

[–] foobaz 1 points 4 months ago

Are there any updates on DUs in C#? I feel like the linked proposal was opened a decade ago by now.

load more comments (2 replies)
load more comments (4 replies)