[swift-evolution] Support for pure setters

Félix Cloutier felixcca at yahoo.ca
Thu Feb 4 11:50:30 CST 2016


I remain unconvinced that any method that starts with "set" without a matching getter could be turned into a "good property setter". I'm not sure who you're trying to convince with this metric.

Maybe you should start by telling if you think that there can be a "bad setter". For instance, can I replace a `sendResponse(String)` method that sends a string over the network with a `response` set-only property?

IMO, a good setter behaves like it's setting a variable, because this is exactly what the assignment operator suggests. That is:
you should be able to replace a sequence of writes to a setter by a single write with the last value and still have essentially the same end result;
you should be able to reorder setter operations and still essentially get the same end result.
"Essentially the same end result" means that it's okay if the logging output is different or if you wasted cycles in the process.

Félix

> Le 4 févr. 2016 à 10:25:14, Jessy Catterwaul <mr.jessy at gmail.com> a écrit :
> 
> My original post from yesterday, which describes the way that I am using set-only properties in Swift, still has not gotten through; attempting again:
> 
> I use set-only properties very, very often. I am interested to know how ubiquitous functions that begin with “set” are, in  frameworks. I’m currently under the impression that people usually don’t recognize that they could be using a setter, instead of a function, due to those frameworks, coming from a respected source, causing them to believe that the practice is reasonable.
> 
> /// Use this as the getter for set-only properties, 
> /// until Swift has real set-only properties.
> ///- Important: Causes a fatal error, logging the name of the property.
> ///- Parameter propertyName: Never use this; only use the default.
> @noreturn public func setOnlyPropertyGetterError(propertyName: String = __FUNCTION__) {
>    fatalError("\(propertyName) is set-only")
> }

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


More information about the swift-evolution mailing list