[swift-evolution] [Discussion]: Deprecate !-Unwrapping of Optionals
Simon Pilkington
simonmpilkington at icloud.com
Wed Mar 2 00:12:19 CST 2016
I’m not sure it is a good idea to make the language syntax more verbose (and less convenient) in an attempt to suggest best practice. If nothing else force-unwrapping is useful in test code and making test code more verbose is definitely a negative.
As mentioned previously in this thread, I think it would be preferable to consider compiler options for warning/restricting its usage in production code - potentially even eventually moving to force-unwrapping being disabled for production code by default.
-Simon
> On 1 Mar 2016, at 9:30 PM, Andrey Tarantsov via swift-evolution <swift-evolution at swift.org> wrote:
>
> Strong -1.
>
> My UI code has hundreds of these force-unwraps, mostly on resource access like UIImage(named: "something")!, to catch naming mistakes and the like. Making it a method will increase the visual noise significantly, and I can't even imagine using let's for this.
>
> In general, I consider ! an assertion, and definitely NOT a code smell. There are many cases where generic code may legitimately return nil, but I as a developer know that it will never happen in my particular case.
>
> A.
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160301/483bd1fc/attachment.html>
More information about the swift-evolution
mailing list