[swift-evolution] [Review] Require self for accessing instance members
preston.sumner at gmail.com
Wed Dec 16 17:51:28 CST 2015
While I acknowledge the issues raised by the proposal, I don’t think they're crucial enough to warrant changing the language.
One concern is that I expect people would simply sidestep the requirement by getting all their accesses through self out of the way early, as they do in Objective-C:
// Store a bunch of local variables to the stuff we want to work with.
let alpha = self.alpha
let beta = self.beta
let gamma = self.gamma
var results = self.results
// Actually do the work we wanted to do.
let result = calculateResultWithAlpha(alpha, beta: beta, gamma: gamma)
As in Objective-C, these preambles can be mildly annoying to read and write, depending on your temperament. More importantly, a bug exists in the example: the results array is a copy, so the calculated result doesn’t get appended to the instance variable as intended. The proposal trades one set of potential gotchas for another, as modifications to internal value types would require either always accessing them through self or remembering to propagate local changes to their respective instance variables at the end of work.
Good points can be made by both sides in favor of preferring a particular style, while no sufficiently persuasive points have yet been made for changing the language to prohibit either one. Thus—like tabs versus spaces or eating bread buttered-side up or buttered-side down—I think this is a style choice better enforced at the project level.
> On Dec 16, 2015, at 11:55 AM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
> Hello Swift community,
> The review of “Require self for accessing instance members” begins now and runs through Sunday, December 20th. The proposal is available here:
> https://github.com/apple/swift-evolution/blob/master/proposals/0009-require-self-for-accessing-instance-members.md <https://github.com/apple/swift-evolution/blob/master/proposals/0009-require-self-for-accessing-instance-members.md>
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> or, if you would like to keep your feedback private, directly to the review manager.
> What goes into a review?
> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a change to Swift?
> * Does this proposal fit well with the feel and direction of Swift?
> * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> More information about the Swift evolution process is available at
> https://github.com/apple/swift-evolution/blob/master/process.md <https://github.com/apple/swift-evolution/blob/master/process.md>
> Doug Gregor
> Review Manager
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution