News for hackers. Stuff that matters.
Re:Null Object Pattern in Swift by panic on Wednesday November 11, 2015 @08:39PM (#10550760)
Re:Null Object Pattern in Swift by eofster on Thursday November 12, 2015 @04:43AM (#10552158)
I now see that my examples are oversimplified. I also don’t think that the Null Object pattern is the ultimate solution for handling nulls. I just found it useful in certain cases.

What I wanted to show here among other things and why optional chaining would not help is if we wanted to have a special case handling on failure. Optional chaining fails silently. So if we wanted to log an error or to terminate the app every time the request fails, we'd have to do it on every function call.

Re:Null Object Pattern in Swift by andrew_mason1 on Wednesday November 11, 2015 @11:40PM (#10551338)
I fail to see how optional chaining, Maybe monads (or Optionals, depending on your persuasion), or the Null Object pattern are fundamentally any different from each other.
Re:Null Object Pattern in Swift by sanderjd on Thursday November 12, 2015 @04:29PM (#10556277)
In languages with good type-checking and optional / maybe types (like Swift, Scala, Rust, Haskell, …), the null object pattern seems less useful, because the compiler makes sure you unwrap things in the right places. But the null object pattern seems really useful in languages like Ruby and Python, where attempting to use optionals tends to just replace null object errors with errors from forgetting to unwrap the value.
Re:Null Object Pattern in Swift by Camillo on Thursday November 12, 2015 @02:49AM (#10551838)
Well, the Null Object Pattern is clearly the worst of the bunch, since it requires a whole lot of extra code to set up. It also introduces maintenance issues since you need to keep adding methods to it. Basically, it's a horrid idea to use in Swift.