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

Brent Royal-Gordon brent at architechies.com
Mon Feb 29 17:29:51 CST 2016


> 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