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

Saagar Jha saagarjha28 at gmail.com
Wed Jun 8 16:46:26 CDT 2016


+1 I agree. Unwrapping in the functional signature is confusing for the
user; many don’t realize that it puts the burden of checking on them.
Non-optional function parameters make this explicit by preventing passing
in Optional types, forcing the user to check, which they should be doing
anyway.

On Wed, Jun 8, 2016 at 12:22 PM J. Charles M. N. via swift-evolution <
swift-evolution at swift.org> wrote:

>
> This confused me at the beginning.
>
> But doesn't Int! In parameter type means the function is awaiting an
> unwrapped value so the user should ensure that it data parameter is
> available, valid, and unwrapped?
>
> --
> J. Charles
>
> > Le 8 juin 2016 à 13:30, Spromicky via swift-evolution <
> swift-evolution at swift.org> a écrit :
> >
> > 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
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-- 
-Saagar Jha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/be39c3b0/attachment.html>


More information about the swift-evolution mailing list