[swift-evolution] Removing var keyword in protocol property reqirements

Tony Allevato tony.allevato at gmail.com
Wed Jan 18 10:41:46 CST 2017

Personally, I don't feel that the problem is big enough to warrant a
breaking change here.

`var` is the general property declaration keyword in Swift for read-write
stored properties and read-only/read-write computed properties. The fact
that you can use `let` in place of `var` under one specific circumstance (a
read-only property backed by a stored variable) doesn't necessarily make
the entire keyword meaningless, IMO. `let` is just a shortcut for a
read-only stored property, and I think dropping it or moving `{ get set }`
elsewhere would be more confusing, since it would be syntactically
inconsistent with how the property is implemented. (Protocol members look
the same as class/struct members with the body removed.)

In general, I'm skeptical of ideas that just aim to protect new or bad
developers from themselves, especially at the expense of consistency.

On Tue, Jan 17, 2017 at 9:39 PM Vinnie Hesener via swift-evolution <
swift-evolution at swift.org> wrote:

> The var keyword in protocol property requirements is misleading.
> From the docs:
> *If a protocol requires a property to be gettable and settable, that
> property requirement cannot be fulfilled by a constant stored property or a
> read-only computed property. If the protocol only requires a property to be
> gettable, the requirement can be satisfied by any kind of property, and it
> is valid for the property to be also settable if this is useful for your
> own code.*
> I feel this is slightly confusing. To conform, I can use let for { get }.
> I can't use var for { get set } if it's computed. This leads me to believe
> that the keyword var has no actual instructional meaning here. It seems
> misplaced to represent "property".
> I think it should be something else, or maybe removed entirely? Isn't {
> get set } enough to describe what this protocol needs? Maybe we can put the
> { get set } in front of the property name?
> I can think of a couple other small benefits of this, but I don't know if
> it will distract from the main discussion. One of them being that it may
> discourage using lets for those new to the language, as most people will
> just lazily copy/paste the declaration.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170118/93747950/attachment.html>

More information about the swift-evolution mailing list