[swift-evolution] [Pitch] Enforce argument order for defaulted parameters

Radosław Pietruszewski radexpl at gmail.com
Thu Mar 31 06:39:31 CDT 2016


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 at 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 at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list