[swift-evolution] [Pitch] Allow trailing argument labels

Haravikk swift-evolution at haravikk.me
Fri Feb 24 09:40:46 CST 2017

> On 23 Feb 2017, at 18:25, Vladimir.S <svabox at gmail.com> wrote:
> Weird idea, why not have function name just after arguments block, without any separator:
> func adding(_ other:Self) -> Self
> func adding(_ other:Self)reportingOverflow -> (Self, Bool)
> let resultOnly = a.adding(b)
> let resultReportingOverflow = a.adding(b)reportingOverflow

Interesting, but personally I think it's less clear than with the colon separating it further.

> But again, I *do* believe such syntax improvements will not be approved by core team(and most likely by the community). Is it worth to discuss this?

I think if there's going to be a proposal then it helps to have hashed out some of the syntax at least, but yeah, I suppose the key point is whether the feature is significant enough to warrant support. Personally I'm heavily in favour, as I dislike verbose naming and really like the idea of grouped functions being identically named. After all, in the case of protocol oriented integers the adding examples are both an addition operation, all that really differs is the type of result you want from it.

The question I suppose might partly come down to naming convention though; do people like the convention of using a "selector" to narrow the method, versus differently (but otherwise very similarly) named methods. I like how clean just having functions named "adding" is, with the option to narrow to a specific one other than the default, but others may prefer more verbose method names, in which case the feature isn't really needed, if that's the majority view.

I just like that if a group of methods all have the same name it is absolutely clear that they are closely related. The trade-off perhaps however is that narrowing down the choice comes later, whereas using the method name means narrowing down of auto-correct happens right away.

More information about the swift-evolution mailing list