[swift-evolution] [Proposal] Remove force unwrapping in function signature.

Spromicky spromicky at gmail.com
Sat Jun 25 10:13:05 CDT 2016


So, its proposal is dead, or what we must to do to force it to swift-evolution repo on GitHub?

> Hello, everyone!
> 
> I wanna propose to you to remove force unwrapping in fuction signature for swift code. That no sense in clear swift code. If we wanna use some optional value as function param, that is not optional, we must unwrap it before function call.
> People who new in swift look at how they old Obj-C code (without nullability modifiers) translate in to swift:
> 
> Obj-C:
> - (void)foo:(NSInteger)bar {
> //...
> }
> 
> Swift transaliton:
> func foo(bar: Int!) {
> //...
> }
> 
> And think that force unwrapping in signature is good practice. And start write functions in clear swift code like this:
> 
> func newFoo(bar: Int!) {
> //...
> }
> 
> and use it like this:
> 
> let bar: Int? = 1
> newFoo(bar)
> 
> And it really work, and they does not think that this can crash in case if `bar` will be `nil`.
> But in clear swift we wanna work with parametrs in function that clearly or optional, or not.
> 
> func newFoo(bar: Int) {
> //...
> }
> 
> or
> 
> func newFoo(bar: Int?) {
> //...
> }
> 
> When we write a new function we know what we need in this case and use optional params or not.
> 
> So my proposal is remove force unwrapping(`!`) from function signatures, cause it have no sense, and that confuse new users.
> 
> 
> 


More information about the swift-evolution mailing list