[swift-evolution] [Proposal Draft] Flexible memberwise initialization
Alex Johnson
ajohnson at quickleft.com
Wed Jan 6 14:49:30 CST 2016
Hopefully this is still the right place to discuss this proposal (it's listed
as being in active review
<https://github.com/apple/swift-evolution/blob/master/schedule.md>, but I
don't see a separate [Review] thread).
I like this proposal. I think it will bring some much-needed ease-of-use.
I'm not sold on the "..." placeholder for the memberwise arguments, though.
I know this was suggested by Chris Lattner, so I'm tempted to defer to his
judgement. But here are my thoughts:
First, it's very close to the varags syntax (e.g. "Int...") which can also
appear in initializer argument lists.
Second, and I think more important, I'm not sure that it's all that *useful*.
Aside from being used to mark the initializer as having "memberwise"
semantics, which is already done by the "memberwise" keyword, the most
common example I've seen is code like this:
memberwise init(customArg: Int, ...) {
/* use customArg */
}
That is, it's used to indicate where the synthesized arguments appear in
the argument list if there are also custom (non-memberwise) arguments.
My question is, *why not always put the memberwise arguments last?* That
would eliminate the need for the placeholder (aka "...").
I don't think I've seen a compelling case for embedding the "..." *within* a
list of custom arguments, like:
memberwise init(customArg1: Int, ..., customArg2: Int) {
/* use customArg1 and customArg2 */
}
And it's been mentioned several times that this is purely additive. If
there *is* an obscure case where that is useful, the author can write use
manual initialization.
On Wed, Jan 6, 2016 at 6:48 AM, Thorsten Seitz via swift-evolution <
swift-evolution at swift.org> wrote:
> Ok, that makes sense.
>
> -Thorsten
>
> > Am 03.01.2016 um 00:24 schrieb Chris Lattner <clattner at apple.com>:
> >
> >
> >> On Jan 2, 2016, at 2:48 PM, Thorsten Seitz <trsfoo at googlemail.com>
> wrote:
> >>
> >> One question just occurred to me: do we really need the keyword
> „memberwise“ anymore? Wouldn’t just using "init(…)“ be sufficient?
> >
> > It wouldn’t be necessary to make the parser work, but I think we’d want
> something to make it clear what was intended. Otherwise, you could write:
> >
> > init(a : Int, …)
> >
> > when you meant:
> > init(a : Int …)
> >
> > and unfortunate things would happen. The memberwise keyword also makes
> it much more clear to the reader what is going on.
> >
> > -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
--
*Alex Johnson | Engineering Lead*
*Quick Left, Inc. <https://quickleft.com/>*
*Boulder **|* *Denver* *|* *Portland** |** San Francisco*
1 (844) QL-NERDS
@nonsensery
<https://github.com/quickleft> <https://www.facebook.com/quickleft>
<https://twitter.com/quickleft> <https://instagram.com/quick_left/>
<https://www.flickr.com/photos/quickleft> <https://vimeo.com/quickleft>
*What's it like to work with us? **TrainingPeaks, iTriage, and Ping
Identity share their stories in this short video** A Client's View
<https://vimeo.com/92286352>*.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160106/7e8b3d8d/attachment.html>
More information about the swift-evolution
mailing list