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

Jeremy Pereira jeremy.j.pereira at googlemail.com
Wed Jan 18 04:37:06 CST 2017

> On 18 Jan 2017, at 05:38, 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?

-1 from me

I’d rather keep the syntax for protocols as similar as possible to the syntax for classes and structs. 

There might be an argument for `let` in a protocol as well as `var` although that would really be allowing protocol designers to dictate implementation details to designers of structs and classes that implement the protocol.

> 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

More information about the swift-evolution mailing list