3 ms·
> [Using Optional] mean that wrong code look wrong ...as long as you don’t use any implicitly unwrapped optionals (which virtually all Mac/iOS code does), or u
by ken 8y ago
> [Using Optional] mean that wrong code look wrong
...as long as you don’t use any implicitly unwrapped optionals (which virtually all Mac/iOS code does), or use any frameworks that predate Swift (like AppLit/UIKit/Foundation), or wrap any C libraries (most third-party libraries in the world).
So basically that’s true for the 5-line samples showing how cool Optional is, and no real program I’ve ever written. It was a nice experiment but in practice I have more issues stemming from Optional than I ever did with nil.
> In contrast: bad.shit.happends
Do you not read any Swift forums? There are newbies posting every single day asking why "a.b.c" crashed in Swift.
- mamcx 8y ago> There are newbies posting every single day asking why "a.b.c" crashed in Swift. That is fair. And totally show why optionals are the right thing. Because obj-c and others NOT have it the world suck MUCH more. That is why nulls are the billon dollar MISTAKE with capital letters. The solution is to more and more languages, libraries and frameworks embrace the idea of algebraic types, not just declare "interfacing with old codebases with this huge MISTAKE is not nice, so why bother??". What rust make nice is declare stuff as UNSAFE. I wish this was the case with swift and obj-c so make clear to everyone that you have entered the realm of nasty things and must be more careful...
- wool_gather 8y agoObjective-C has "optionals": every object pointer can be `nil`. What it gets right is that it doesn't implicitly treat a `nil` as a logic failure.
- mamcx 8y agoThat is not optionals, at all.