Conversation

New rule! API documentation writers. Does it return null or throw an exception? How does it behave if the problem is unsolvable? What order does the array items appear in? If undefined, please write that it's undefined.
3
6
Ah, I am so happy to be writing Swift nowadays. You can never return null unless you specifically say so in your type, and you have to always have code that handles the nulls. Still, documenting all the possible reasons something might return null would still be great.
1
2
That does sound awesome! On the other hand, I'm actually super comfortable juggling a bunch of nulls around, I just think API documentations should be very clear whether it'll return null or throw an exception if it couldn't return a thing.
2
1
You can have your cake and eat it too - you just explicitly 'opt-in' to nullability when you want it. In some languages you call it `T?`, in others it's `Option<T>`. Swift, Rust, Kotlin, C# 8.0, Haskell, etc. all have this lovely feature - thankfully it's becoming more popular!
2
1
The <T> makes me think of generic classes/method (but maybe it means something else in other languages). But yeah, looks like C# 8.0 is indeed getting better ways to control whether things can be null or not, which is great!
1
Yeah, in Rust for example you have: enum Option<T> { Some(T), None, } So it can either be something or nothing. No value can ever be null in Rust, so it effectively gives you opt-in nullability. Likewise you have: enum Result<T, E> { Ok(T), Err(E), }
1
Ah, okay! Yeah, the first has been around in C# as Nullable<T>. Excited to see what will be added in C# 8 though.
2