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

Vinnie Hesener vhesener at gmail.com
Tue Jan 17 23:38:21 CST 2017


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170117/d33c9410/attachment-0001.html>


More information about the swift-evolution mailing list