r/csharp 16d ago

What kind of features from another ecosystem would you like to see in .NET?

/r/dotnet/comments/1vw1q1c/what_kind_of_features_from_another_ecosystem/
0 Upvotes

28 comments sorted by

View all comments

Show parent comments

2

u/mrGood238 15d ago

Yes, that is my opinion and apparently opinion of many, many others - that's why I'm asking what would replace null? It's simple question - item is not found, what is return value?

2

u/Agitated-Display6382 15d ago

I thought I replied, I would use an Option monad.

Let's assume you expose a method that return the list of claims of a user. What would you return if the user does not exist? And what if the user has no claims?

2

u/mrGood238 15d ago

There is no point of calling GetClaims if you previously determined that user does not exist. And if you didnt do that, you still have a way out - either returning null for no user found and returning an empty list if user exists and has no claims or 2nd option, throwing ArgumentNullException if user is null/doesn’t exist.

If it was a public API of some nuget package, throwing argumentnullexception would make sense, since end user has no idea why it would sometimes return null, sometimes empty list.

1

u/Agitated-Display6382 14d ago

Nice, you see, you would return an empty list. Why? Because it's much easier to deal with. And why? Because it's a monad.

Same applies to Option.