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

Charlie Monroe charlie at charliemonroe.net
Sun Jun 26 23:28:15 CDT 2016


See https://github.com/apple/swift-evolution/blob/master/process.md - you would need to make an official proposal and submit it as pull request. But given the reaction here, it's unlikely to get approved.

Also, the ObjC code without nullability is getting fairly rare - all Apple's frameworks are with nullability information (as far as I've checked) in macOS 10.12, iOS 10. Third party libraries should be updated to use nullability (and most libraries that are maintained already do).


> On Jun 25, 2016, at 5:13 PM, Spromicky via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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.
>> 
>> 
>> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list