[Proposal Draft] Flexible memberwise initialization

(Thorsten Seitz) #1




Am 06. Januar 2016 um 21:49 schrieb Alex Johnson via swift-evolution swift-evolution@swift.org:

Hopefully this is still the right place to discuss this proposal (it’s listed as being in active review, 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@swift.org wrote:

Ok, that makes sense.


Am 03.01.2016 um 00:24 schrieb Chris Lattner clattner@apple.com:

On Jan 2, 2016, at 2:48 PM, Thorsten Seitz trsfoo@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.


swift-evolution mailing list

Alex Johnson | Engineering Lead

Quick Left, Inc.

Boulder |Denver| Portland** |** San Francisco

1 (844) QL-NERDS


What’s it like to work with us? TrainingPeaks, iTriage, and Ping Identity share their stories in this short video* A Client’s View*.

swift-evolution mailing list