[Pitch] Enforce argument order for defaulted parameters


(Joe Groff) #1

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe


(William Dillon) #2

As long as you can still provide an overriding value to only one of the defaulted parameters I probably wouldn't miss it. I would hate to have to re-state the default value of all the parameters up to the one I want to change, though.

- Will

···

On Mar 30, 2016, at 9:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(Erica Sadun) #3

While I do take advantage of this feature, it would be less than honest to point out that a large portion of such
usage is to point out how cool the ability is.

That said, what I'm really doing is treating them in code like an ad hoc set of enumerated cases with associated
values. Perhaps rethinking about them in that light would be better than simply removing them from the
language?

-- E

···

On Mar 30, 2016, at 10:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe


(Sune Foldager) #4

Yes I think it would be fine to remove, as long as you can still leave out arguments you just want the default values for, of course (otherwise there wouldn’t be much use of default left). I doubt many people directly exploit this feature, although it probably happens here and there by accident. I always try to keep the same order as the signature.

—Sune

···

On 30 Mar 2016, at 09:59, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(Russ Bishop) #5

Now that we’re labelling the first argument it is only inconsistent because you can’t arbitrarily reorder the required named parameters, though that’s not something I feel strongly about.

I personally like it because I consider the defaulted parameters to be “extra add-ons” or the alternative to a “userInfo: [String: AnyObject]” pattern.

I’d vote to leave things as-is unless it imposes a significant maintenance cost on the compiler.

Russ

···

On Mar 30, 2016, at 9:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?


(Sean Heber) #6

I use this feature from time to time, but not usually intentionally. I appreciate that it doesn't force me to rearrange a bunch of parameters at call sites just because I happen to change the order of them in the function declaration, though.

l8r
Sean

···

Sent from my iPhone

On Mar 30, 2016, at 11:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(Matthew Johnson) #7

One place where I believe argument re-ordering is useful is with memberwise arguments when you are initializing an instance. Order usually plays no significant role with these arguments which are in some sense similar to assignment statements (which are inherently re-orderable).

In fact, I have found myself wishing non-defaulted memberwise initializer parameters were re-orderable at times, especially when using the implicit memberwise initializer for a struct. Source order for property declarations does not always match what makes the most sense at the initialization site (something that was pointed out numerous times during the review of my memberwise init proposal).

Matthew

···

On Mar 30, 2016, at 11:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(Jeff Kelley) #8

I have never taken advantage of this, personally. Given that there isn’t anything that this feature enables that can’t be done if it’s removed—aside from reordering arguments—I’d be in favor of removing it for simplicity’s sake.

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/>

···

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe


(Radek Pietruszewski) #9

I think this ability to reorder labeled parameter names is more useful in a dynamic language like Ruby than in Swift, since Ruby doesn’t give my text editor the ability to autocomplete the function signature. If I’m typing the function and its arguments from my head, I’m more likely to forget the “right” order. With Swift, I’d generally start typing the name and have Xcode autocomplete all available parameters for me, ensuring the original order.

I think defaulted parameters are different from required parameters in that they’re usually not “inputs” but “options”, and therefore the order of them really doesn’t matter — and they’re not _really_ part of the API name. And so the distinction makes sense to me.

And it still makes sense to me that I would want to modify some function call and just add a parameter at the end, without Xcode’s assistance, and regardless of the original order.

So: I believe there’s utility in this feature, and the complexity to the language is negligible (I think a lot of people won’t really “discover” this feature, but will just naturally write something valid without the compiler bothering them needlessly). If there’s significant complexity in the implementation of this feature, I wouldn’t be super sad if it went away, but if there isn’t, I’d prefer that it stays.

— Radek

···

On 30 Mar 2016, at 18:59, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(Ilya Belenkiy) #10

I think that it’s very useful (I use it frequently in unit tests). I hope that this stays the way it is now.

···

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

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


(William Dillon) #11

I think Matthew and Erica bring up good points here.

When considering this change, it's worthwhile considering the effect it would have on the package manager (among the other cases that they may use privately). Currently, the package.swift's centerpiece is the initialization of the Package class. If strict ordering is enforced would that lead to undue confusion when people naively reorder the setting of these parameters?

- Will

···

On Mar 30, 2016, at 11:20 AM, Matthew Johnson via swift-evolution <swift-evolution@swift.org> wrote:

One place where I believe argument re-ordering is useful is with memberwise arguments when you are initializing an instance. Order usually plays no significant role with these arguments which are in some sense similar to assignment statements (which are inherently re-orderable).

In fact, I have found myself wishing non-defaulted memberwise initializer parameters were re-orderable at times, especially when using the implicit memberwise initializer for a struct. Source order for property declarations does not always match what makes the most sense at the initialization site (something that was pointed out numerous times during the review of my memberwise init proposal).

Matthew

On Mar 30, 2016, at 11:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe
_______________________________________________
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


(Sean Heber) #12

Yes, absolutely this - I'd likely be fine with the order of them being strict, but being able to omit ones that I want to be defaulted is a must.

l8r
Sean

···

Sent from my iPhone

On Mar 30, 2016, at 12:06 PM, William Dillon via swift-evolution <swift-evolution@swift.org> wrote:

As long as you can still provide an overriding value to only one of the defaulted parameters I probably wouldn't miss it. I would hate to have to re-state the default value of all the parameters up to the one I want to change, though.

- Will

On Mar 30, 2016, at 9:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe
_______________________________________________
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


(Thorsten Seitz) #13

+1

-Thorsten

···

Am 30.03.2016 um 19:06 schrieb William Dillon via swift-evolution <swift-evolution@swift.org>:

As long as you can still provide an overriding value to only one of the defaulted parameters I probably wouldn't miss it. I would hate to have to re-state the default value of all the parameters up to the one I want to change, though.

- Will

On Mar 30, 2016, at 9:59 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe
_______________________________________________
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


(Howard Lovatt) #14

As William said, so long as you can still omit unused arguments.

···

On Thursday, 31 March 2016, William Dillon via swift-evolution < swift-evolution@swift.org> wrote:

As long as you can still provide an overriding value to only one of the
defaulted parameters I probably wouldn't miss it. I would hate to have to
re-state the default value of all the parameters up to the one I want to
change, though.

- Will

> On Mar 30, 2016, at 9:59 AM, Joe Groff via swift-evolution < > swift-evolution@swift.org <javascript:;>> wrote:
>
> Many people are surprised when they find out defaulted parameters can be
reordered, unlike required arguments. This special case adds complexity to
the language, and runs against our general trend of treating argument
labels as a significant part of an API's name, and preferring a single way
of writing API calls. I think it's worth revisiting this design choice—is
the special case worth the complexity? How many people take advantage of
default argument reordering?
>
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org <javascript:;>
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <javascript:;>
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-- Howard.


(Andrey Tarantsov) #15

I personally like it because I consider the defaulted parameters to be “extra add-ons” or the alternative to a “userInfo: [String: AnyObject]” pattern.

I’d vote to leave things as-is unless it imposes a significant maintenance cost on the compiler.

Strong +1. Please leave it be, it's a useful feature in a small but important subset of cases.

A.


(Robert Widmann) #16

+1

~Robert Widmann

2016/03/31 10:26、Jeff Kelley via swift-evolution <swift-evolution@swift.org> のメッセージ:

···

I have never taken advantage of this, personally. Given that there isn’t anything that this feature enables that can’t be done if it’s removed—aside from reordering arguments—I’d be in favor of removing it for simplicity’s sake.

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan | jeffkelley.org

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe

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


(Dave Abrahams) #17

Seeing some examples with an explanation of how this capability is
important in those examples would be very helpful.

···

on Mon Apr 04 2016, Ilya Belenkiy <swift-evolution@swift.org> wrote:

I think that it’s very useful (I use it frequently in unit tests). I
hope that this stays the way it is now.

--
Dave


(Thorsten Seitz) #18

I think that it’s very useful (I use it frequently in unit tests). I hope that this stays the way it is now.

Do you really use the ability to reorder the arguments or just the ability to omit any combination of default arguments?

-Thorsten

···

Am 04.04.2016 um 13:00 schrieb Ilya Belenkiy via swift-evolution <swift-evolution@swift.org>:

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be reordered, unlike required arguments. This special case adds complexity to the language, and runs against our general trend of treating argument labels as a significant part of an API's name, and preferring a single way of writing API calls. I think it's worth revisiting this design choice—is the special case worth the complexity? How many people take advantage of default argument reordering?

-Joe
_______________________________________________
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


(Javier Soto) #19

I have never taken advantage of this. In fact, I didn't know this was
possible until just now :slight_smile: and I would've definitely found it confusing to
see a function call with "out of order" parameters.

···

On Thu, Mar 31, 2016 at 7:58 AM Developer via swift-evolution < swift-evolution@swift.org> wrote:

+1

~Robert Widmann

2016/03/31 10:26、Jeff Kelley via swift-evolution <
swift-evolution@swift.org> のメッセージ:

I have never taken advantage of this, personally. Given that there isn’t
anything that this feature enables that can’t be done if it’s removed—aside
from reordering arguments—I’d be in favor of removing it for simplicity’s
sake.

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
jeffkelley.org

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution < > swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be
reordered, unlike required arguments. This special case adds complexity to
the language, and runs against our general trend of treating argument
labels as a significant part of an API's name, and preferring a single way
of writing API calls. I think it's worth revisiting this design choice—is
the special case worth the complexity? How many people take advantage of
default argument reordering?

-Joe

_______________________________________________
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

--
Javier Soto


(TJ Usiyan) #20

+1

I use it but won't fight for it or miss it.

···

On Thu, Mar 31, 2016 at 12:45 PM, Javier Soto via swift-evolution < swift-evolution@swift.org> wrote:

I have never taken advantage of this. In fact, I didn't know this was
possible until just now :slight_smile: and I would've definitely found it confusing to
see a function call with "out of order" parameters.
On Thu, Mar 31, 2016 at 7:58 AM Developer via swift-evolution < > swift-evolution@swift.org> wrote:

+1

~Robert Widmann

2016/03/31 10:26、Jeff Kelley via swift-evolution <
swift-evolution@swift.org> のメッセージ:

I have never taken advantage of this, personally. Given that there isn’t
anything that this feature enables that can’t be done if it’s removed—aside
from reordering arguments—I’d be in favor of removing it for simplicity’s
sake.

Jeff Kelley

SlaunchaMan@gmail.com | @SlaunchaMan <https://twitter.com/SlaunchaMan> |
jeffkelley.org

On Mar 30, 2016, at 12:59 PM, Joe Groff via swift-evolution < >> swift-evolution@swift.org> wrote:

Many people are surprised when they find out defaulted parameters can be
reordered, unlike required arguments. This special case adds complexity to
the language, and runs against our general trend of treating argument
labels as a significant part of an API's name, and preferring a single way
of writing API calls. I think it's worth revisiting this design choice—is
the special case worth the complexity? How many people take advantage of
default argument reordering?

-Joe

_______________________________________________
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

--
Javier Soto

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