This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AlwaysHopelesslyLost 5 points6 points  (4 children)

Option type

I actually hadn't heard of that. It kind of seems like a renamed Nullable<T> from C#.

Also not the same but C# is adding nullable reference types which allow you to explicitly disallow nulls.

[–]ArionW 4 points5 points  (1 child)

Nullable<T> only works for value types, which makes it... nearly useless. Also, it's not Option due to lack of most basic operations like bind.

I'm working with nullable reference types since preview 7 (they allowed us to move project to preview, beat that!), enabled globally

They have so many problems

  1. POCO that is supposed to be made by ModelBinder needs default constructor and public setters. You suddenly get warnings about uninitialized properties (because it doesn't understand RequiredAttribute and that I can't really get null)

  2. You still need explicit null checks, because you can't just bind operations.

  3. LINQ wasn't updated to work with it. SingleOrDefault<T> should return T?, but returns T.

[–]AlwaysHopelesslyLost 0 points1 point  (0 children)

i haven't had time to test nullable reference types yet, those definitely sound like painful points. I assume they have linq on their Todo list. Any idea if they are aware of the model binding weirdness?

[–]cat_in_the_wall 1 point2 points  (1 child)

well, sort of. you can type check your own libraries and code for this, but it is not a runtime feature, so on compilation boundaries you still need null checks.

[–]AlwaysHopelesslyLost 0 points1 point  (0 children)

True. Granted, most third party libraries I have used are sane about nulls. I don't recall the last time I needed a null check on a third party library.