[swift-evolution] [Proposal] Warn about implicit property access in own setter

Colin Cornaby colin.cornaby at mac.com
Tue Dec 15 20:50:17 CST 2015


I’d be in favor of this. I was trying this out in a Playground and was trying to remember what the implicit keyword was to get the changed value. Migration wouldn’t be bad. newValue could just be added as an explicitly named parameter to setters that have none. I’m not a fan of these corners of Swift where things are so implicit. But this seems to me to be a problem with Swift where the behavior of the setter is non-obvious enough a developer could slip up. I’d be especially worried about users that are new to the language or new to development making this mistake.

I can understand the counter argument of wanting the shorthand to be present for reducing code cruft. But from my perspective it’s reducing visibility and readability. At the very least, the more compact usage doesn’t feel natural to me. But maybe that’s just me.

> On Dec 15, 2015, at 6:39 PM, Dennis Lysenko via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Other possible solution: why not just remove the default "newValue" and force the user to manually specify it instead?
> 
> 
> On Tue, Dec 15, 2015, 6:02 PM Marc Knaup via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Hello everyone,
> 
> I would like to propose yielding a warning when a property's getter is used from within its setter implicitly without using "self.".
> 
> This can lead to programming errors which are very easy to miss and lead to unexpected behavior at runtime.
> 
> Check out the full proposal here:
> https://github.com/fluidsonic/swift-evolution/blob/master/proposals/NNNN-warn-about-implicit-property-access-in-own-setter.md <https://github.com/fluidsonic/swift-evolution/blob/master/proposals/NNNN-warn-about-implicit-property-access-in-own-setter.md>
> 
> Thank you,
>   Marc
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>  _______________________________________________
> 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/20151215/12e41e07/attachment.html>


More information about the swift-evolution mailing list