Requesting default values for Cocoa/Cocoa Touch APIs


(Erica Sadun) #1

Is there a best way to request default values for common Cocoa and Cocoa Touch APIs?
Now that we're moving to Swift, the language supports defaults and omitted parameters
but the ObjC APIs do not (yet) supply them.

For example, dismissViewControllerAnimated(flag: true, completion: nil)
could become dismissAnimated() when default values are available for flag and completion.
There's a large-ish class of these boilerplate defaults and it would be nice if there were a way to
be able to request them.

cc'ing in Daniel S whose idea this is.

Thanks, -- E


(Daniel Steinberg) #2

Thank you Erica,

Chris recently noted that UIColor.blackColor() will become UIColor.black() and dismissViewControllerAnimated(true, completion: nil) will become dismissAnimated(true, completion: nil).

This latter prompted me to wonder - as the first parameter’s name is flag and first labels will be exposed shouldn’t this be

dismiss(animated: true, completion: nil)

This, in turn led me to ask - don’t we most often want the first parameter to be true and the second to be nil? It is only an exceptional case where we don’t. Why don’t we take advantage of Swift’s default parameters to let this be

dismiss()

Similarly, UIButtons in UIKit stand out from UILabel’s and other widgets when we get and set titles/text. In the pair title(forState:), set(title:, forState:), we we took advantage of the default value .Normal for state then we’d have calls like this

button.title()
button.setTitle(“Hello”)

and only call out the state in cases where we were setting the title for a non-Normal state.

Erica raises the general question that results: there are many defaults like this that would make Swift code read more naturally when working with non-exceptional cases and would call out when we are working with exceptional cases.

Is there a proper way in which to request such an audit/changes? I understand that that may be a Foundation/Cocoa Evolution issue and not a Swift evolution issue.

It does break code - but so does changing dismissViewControllerAnimated to dismissAnimated - it seems that paying the price once would be desirable.

Best,

Daniel

···

On Apr 8, 2016, at 1:40 PM, Erica Sadun <erica@ericasadun.com> wrote:

Is there a best way to request default values for common Cocoa and Cocoa Touch APIs?
Now that we're moving to Swift, the language supports defaults and omitted parameters
but the ObjC APIs do not (yet) supply them.

For example, dismissViewControllerAnimated(flag: true, completion: nil)
could become dismissAnimated() when default values are available for flag and completion.
There's a large-ish class of these boilerplate defaults and it would be nice if there were a way to
be able to request them.

cc'ing in Daniel S whose idea this is.

Thanks, -- E


(Russ Bishop) #3

Wouldn’t this be the responsibility of UIKit/AppKit teams to provide extensions that pass the default values?

Russ

···

On Apr 8, 2016, at 10:40 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

Is there a best way to request default values for common Cocoa and Cocoa Touch APIs?
Now that we're moving to Swift, the language supports defaults and omitted parameters
but the ObjC APIs do not (yet) supply them.

For example, dismissViewControllerAnimated(flag: true, completion: nil)
could become dismissAnimated() when default values are available for flag and completion.
There's a large-ish class of these boilerplate defaults and it would be nice if there were a way to
be able to request them.

cc'ing in Daniel S whose idea this is.

Thanks, -- E
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Dave Abrahams) #4

Wouldn’t this be the responsibility of UIKit/AppKit teams to provide extensions
that pass the default values?

Yup. Please file radars against those components.

···

on Mon Apr 11 2016, Russ Bishop <swift-evolution@swift.org> wrote:

Russ

    On Apr 8, 2016, at 10:40 AM, Erica Sadun via swift-evolution > <swift-evolution@swift.org> wrote:

    Is there a best way to request default values for common Cocoa and Cocoa
    Touch APIs?
    Now that we're moving to Swift, the language supports defaults and omitted
    parameters
    but the ObjC APIs do not (yet) supply them.

    For example, dismissViewControllerAnimated(flag: true, completion: nil)
    could become dismissAnimated() when default values are available for flag
    and completion.
    There's a large-ish class of these boilerplate defaults and it would be nice
    if there were a way to
    be able to request them.

    cc'ing in Daniel S whose idea this is.

    Thanks, -- E
    _______________________________________________
    swift-evolution mailing list
    swift-evolution@swift.org
    https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
Dave


(Erica Sadun) #5

Wouldn’t this be the responsibility of UIKit/AppKit teams to provide extensions
that pass the default values?

Yup. Please file radars against those components.

To clarify: radars, bugreport.apple.com <http://bugreport.apple.com/>, and not bugs.swift.org <http://bugs.swift.org/>, right? Also, any best
tips for getting them noticed? Anyone in particular we can ping on Twitter or via
email with radar numbers?

-- E

···

On Apr 11, 2016, at 4:32 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:
on Mon Apr 11 2016, Russ Bishop <swift-evolution@swift.org> wrote:

Russ

   On Apr 8, 2016, at 10:40 AM, Erica Sadun via swift-evolution >> <swift-evolution@swift.org> wrote:

   Is there a best way to request default values for common Cocoa and Cocoa
   Touch APIs?
   Now that we're moving to Swift, the language supports defaults and omitted
   parameters
   but the ObjC APIs do not (yet) supply them.

   For example, dismissViewControllerAnimated(flag: true, completion: nil)
   could become dismissAnimated() when default values are available for flag
   and completion.
   There's a large-ish class of these boilerplate defaults and it would be nice
   if there were a way to
   be able to request them.

   cc'ing in Daniel S whose idea this is.

   Thanks, -- E
   _______________________________________________
   swift-evolution mailing list
   swift-evolution@swift.org
   https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #6

Switching to Swift-Users: Daniel Steinberg and I want to expand SE-0005-like defaults to common Cocoa and Cocoa-Touch patterns. This discussion really doesn't fall under Swift-Evolution so I've cc'ed in Swift-Users for further discussion (Please drop Swift-Evolution in your replies)

We've set up a gist: https://gist.github.com/erica/3987ec54b8f4a580ae5fc18f4e9e7ca5 with our preliminary suggestions.

Thanks in advance for any feedback,

-- Erica

···

On Apr 11, 2016, at 4:32 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Mon Apr 11 2016, Russ Bishop <swift-evolution@swift.org> wrote:

Wouldn’t this be the responsibility of UIKit/AppKit teams to provide extensions
that pass the default values?

Yup. Please file radars against those components.


(Dave Abrahams) #7

        Wouldn’t this be the responsibility of UIKit/AppKit teams to provide
        extensions
        that pass the default values?

    Yup. Please file radars against those components.

To clarify: radars, bugreport.apple.com, and not bugs.swift.org,
right?

Right.

Also, any best tips for getting them noticed? Anyone in particular we
can ping on Twitter or via email with radar numbers?

Wish I had ideas for you on this. Maybe someone else does.

···

on Mon Apr 11 2016, Erica Sadun <erica-AT-ericasadun.com> wrote:

    On Apr 11, 2016, at 4:32 PM, Dave Abrahams via swift-evolution > <swift-evolution@swift.org> wrote:
    on Mon Apr 11 2016, Russ Bishop <swift-evolution@swift.org> wrote:

-- E

        Russ

        On Apr 8, 2016, at 10:40 AM, Erica Sadun via swift-evolution > <swift-evolution@swift.org> wrote:

        Is there a best way to request default values for common Cocoa and Cocoa
        Touch APIs?
        Now that we're moving to Swift, the language supports defaults and
        omitted
        parameters
        but the ObjC APIs do not (yet) supply them.

        For example, dismissViewControllerAnimated(flag: true, completion: nil)
        could become dismissAnimated() when default values are available for
        flag
        and completion.
        There's a large-ish class of these boilerplate defaults and it would be
        nice
        if there were a way to
        be able to request them.

        cc'ing in Daniel S whose idea this is.

        Thanks, -- E
        _______________________________________________
        swift-evolution mailing list
        swift-evolution@swift.org
        https://lists.swift.org/mailman/listinfo/swift-evolution

        _______________________________________________
        swift-evolution mailing list
        swift-evolution@swift.org
        https://lists.swift.org/mailman/listinfo/swift-evolution

    --
    Dave

    _______________________________________________
    swift-evolution mailing list
    swift-evolution@swift.org
    https://lists.swift.org/mailman/listinfo/swift-evolution

--
Dave