Here is a real world example of where I use defaulted parameters:

public extension UIView {
    public convenience init(
        _ w: CGFloat,
        _ h: CGFloat,
        position: CGPoint = .zero,
        backgroundColor: UIColor = UIColor.whiteColor(),
        translucency alpha: CGFloat = 1.0,
        borderWidth: CGFloat = 0.0,
        borderColor: UIColor = UIColor.blackColor(),
        cornerRadius: CGFloat = 0.0
        ){
        self.init(frame: CGRect(x: position.x, y: position.y, width: w, height: h))
        self.backgroundColor = backgroundColor.colorWithAlphaComponent(alpha)
        self.layer.borderWidth = borderWidth
        self.layer.borderColor = borderColor.CGColor
        self.layer.cornerRadius = cornerRadius
        self.translatesAutoresizingMaskIntoConstraints = false
    }
}


It's not a beautiful initializer or aspirational code. It is convenient for putting together flexible views in playgrounds. This utility controls the axes I typically want to tweak for view creation:

* How big is it  (w, h)
* Where is it? (position, if used, for example, as a subview)
* What color is it? Is the color solid or translucent? (backgroundColor, translucency)
* Does it have a border? and if so, how wide and what color? (borderWidth, borderColor)
* Are the corners rounded and to what degree? (cornerRadius)

The reason I present this example is that while there are relationships between some of the defaulted values, there is absolutely no inherent order to those groups. When putting together a view, I may later decide to add, for example, the border. Should I have to know that the border must appear before any background color settings?

Having to figure out where a previously defaulted value should be inserted when adding an explicit setting imposes an undue burden on the programmer, reduces flexibility during experimentation, and removes one of the neatest Swift features. For this reason, I vote no on the proposal. By rejecting this proposal, Swift retains a flexibility that defers to the programmer, placing the programmer's needs before any benefits that may accrue to the compiler.

I have followed the discussion. I believe it goes against the general Swift philosophy. And while the change being proposed is significant to be part of a formal language review process, I think adopting it would be the wrong thing to do.

-- Erica


On May 3, 2016, at 9:52 PM, Chris Lattner via swift-evolution <[email protected]> wrote:

Hello Swift community,

The review of "SE-0060: Enforcing order of defaulted parameters" begins now and runs through May 9. The proposal is available here:

https://github.com/apple/swift-evolution/blob/master/proposals/0060-defaulted-parameter-order.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

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 contribute to 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 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

Thank you,

-Chris Lattner
Review Manager


_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to