[swift-evolution] [Discussion]: Deprecate !-Unwrapping of Optionals

Developer devteam.codafi at gmail.com
Mon Feb 29 18:04:11 CST 2016


It is guarded in the same way that *(NULL) is guarded by an EXC_BAD_ACCESS.  It is all partiality in the end and beside the point I wished to make at the root of the discussion.  

Bang isn’t going anywhere under the original scheme, its usage is merely getting more obvious.  If you’ll excuse the pun, it’s a sin-tax on the usage of bang that I want, nothing more.  You can always reach for that hammer should you choose, but you will have to pay for it by using a function.  The language shouldn’t encourage thinking with partiality by baking it into its syntax so explicitly.

> On Feb 29, 2016, at 6:29 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> These are equivalent to naked unguarded dereferences in C-like languages and are, we can all agree, a code smell, not a feature.
> 
> I previously wrote a 463-word post in this thread arguing that these are *not* code smells. Maybe you don't agree with that position, but if you really think "we can all agree" it's a code smell, you're not actually listening to the arguments against you.
> 
> I also object to the idea that these are "unguarded" dereferences. `!` *is* guarded by code which always reliably causes a crash if the value is nil. If this unwrap is guarded:
> 
> 	guard let foo = foo else {
> 		fatalError("foo is nil!")
> 	}
> 	doSomething(foo)
> 
> Then so is this:
> 
> 	doSomething(foo!)
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 



More information about the swift-evolution mailing list