[swift-evolution] [Pitch] Make `default` function parameter values more transparent

Антон Жилин antonyzhilin at gmail.com
Mon Jun 13 13:00:03 CDT 2016


-1 to default parameters in protocols.

Default parameters fall into a bad category of function features.
Since I'm bad at explaining things, I'll give an example.

protocol A {
    func call(block: @autoclosure () -> ())
}
protocol B {
    func call(block: () -> ())
}

Now it's impossible to conform to both of these protocols.

@noescape is good, because we can conform to both protocols with a
@noescape function.
`throws` is good, because we can conform to both protocols with a
non-throwing function.

On the other hand, consider a case with defaulted parameters:

protocol A {
    func foo(x: Int = 1)
}
protocol B {
    func foo(x: Int = 2)
}

It's impossible to conform to both protocols at once.
Therefore, default parameters is together with @autoclosure and on the
opposite side of @noescape and `throws`. That is, on "ambiguous" side.
I would prefer to have as few such features as possible.

- Anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160613/8ba3f936/attachment.html>


More information about the swift-evolution mailing list