[swift-evolution] [Review] SE-0018 Flexible Memberwise Initialization

Douglas Gregor dgregor at apple.com
Mon Jan 11 00:37:56 CST 2016

> On Jan 6, 2016, at 2:47 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 	* What is your evaluation of the proposal?

It’s a well-considered and well-written proposal. I agree with the semantics of memberwise initializers (+1 to adding a reasonable implicit memberwise initializer for classes, and the ability to use default arguments in that implicit memberwise initializer). However, I would prefer to accept the semantics as improvements to the creation of the implicit memberwise initializer, so it’s a -1 to the “memberwise” specifier and “…” placeholder syntax.

Separately, I’m moderately nervous about the placeholder “…” getting overloaded with future intended uses for variadic generics and tuple packing/unpacking. I think the syntaxes will be distinct (“…” would always be attached to an existing parameter in the variadic-generics cases, and would be it’s own “parameter” for the memberwise initializer), but it could certainly be confusing.

> 	* Is the problem being addressed significant enough to warrant a change to Swift?

Yes, for the implicit memberwise initializer. The lack of default arguments in the implicit memberwise initializer comes up often as a feature request, and the lack of an implicit memberwise initializer for classes leads to a bunch of boilerplate for common use cases (particularly the “let’s create our first class” example, which needs to mention initializers far too early).

As for the “memberwise” specifier and placeholder syntax, I don’t think so. When the implicit memberwise initializer doesn’t suffice, I think it’s completely reasonable to write out a memberwise initializer directly. It’s still boilerplate, but the cases in which it happens aren’t so numerous that it’s worth having another initialization concept.

> 	* Does this proposal fit well with the feel and direction of Swift?

Yes. It’s eliminating boilerplate and making structs/classes more useful and more uniform.

> 	* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read through the proposal and some of the commentary and, err, I bear responsibility for the current implicit memberwise initializer semantics, and have been thinking about this problem on-and-off for a couple of years.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160110/e1cae902/attachment.html>

More information about the swift-evolution mailing list