by michalc · 2w ago · 0 comments
It's not necessarily always "wrong", but you essentially have to think about "what's the right behaviour on None" a lot more, and while yes the type checker will help avoid runtime errors from random places, I think that can lead to essentially runtime bugs if you answer that question wrong. Or, at best you end up with quite messy data transformation and error handling, which itself can end up as a source of bugs.
One thing I try to ask myself is "what would this look like without `| None`", and take it from there. Also, it isn't `| None` as such, it can be any union type: code can end up with blurry responsibility.
This is what I tend to prefer. Not always possible, but worth striving for.
> One thing I try to ask myself is "what would this look like without `| None`", and take it from there. Also, it isn't `| None` as such, it can be any union type: code can end up with blurry responsibility.
Yeah, unions can be problematic, but at least they're more legible than None as this can basically break everything.