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.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to