Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 13
    Yes. Many people argue "What's the difference whether I have an if statement checking for NULL or an if statement checking for None", but the point is, if you are checking your Options, then you are doing it wrong. Commented May 28, 2020 at 0:14
  • 2
    "Use this wisely and it makes code easier to read". Agreed. Objective-C silently swallows method calls on nil objects, and so apps don't crash, but then they proceed with missing data. However you do it, you do need to ensure that your program has all the data it needs. "watch it quietly do nothing" and that can be a problem. Fail early, fail fast. Commented May 28, 2020 at 16:15
  • 4
    Pass me a null and I have to check for null once. Pass me an Option and I have to use map on it every time I want to do something interesting. The difference is one of preference. Option is equivalent to a static null check that leverages the type system instead of some other compile-time checking mechanism. Commented May 28, 2020 at 20:20
  • 1
    @Beefster option doesn’t always take on a value at compile time. Commented May 28, 2020 at 20:29
  • 1
    @Beefster You could just extract the wrapped object from the Option, then operate on that, or handle the None case the same as you would have if your reference was null. Same effort as a single null check, but with the added benefit that you can't forget to do it. Commented May 29, 2020 at 20:24