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.

9
  • 8
    ...because figuring out who generated (or rather, didn't bother to change or initialize) the garbage data that is filling your supposedly useful object is so much easier than tracking a NULL reference? I don't buy it, although I'm mostly stuck in statically typed land. Commented Oct 19, 2010 at 0:00
  • Garbage data is so much rarer than null references, though. Particularly in managed languages. Commented Oct 19, 2010 at 1:05
  • 6
    -1 for Null Object. Commented Jul 13, 2012 at 22:18
  • 5
    Points (4) and (5) are solid, but the NullObject is not a remedy. You will fall into even worse trap -- logic (workflow) errors. When you know EXACTLY the current situation, sure, it can help, but using it blindly (instead of null) will cost you more. Commented May 22, 2013 at 13:29
  • 1
    @gnasher729, while Objective-C's runtime won't throw a null-pointer exception like Java and other systems do, it doesn't make using null references any better for the reasons I outlined in my answer. For example, if there's no navigationController in [self.navigationController.presentingViewController dismissViewControllerAnimated: YES completion: nil]; the runtime treats it as a sequence of no-ops, the view isn't removed from the display, and you might sit in front of Xcode scratching your head for hours trying to figure out why. Commented Apr 13, 2015 at 2:31