[swift-evolution] [Pitch] Make `default` function parameter values more transparent
Haravikk
swift-evolution at haravikk.me
Mon Jun 13 12:06:57 CDT 2016
> On 13 Jun 2016, at 15:52, Erica Sadun <erica at ericasadun.com> wrote:
>
> I'm not sure what enhancing defaults would look like, especially for protocols. Are you suggesting if there's a protocol like:
>
> protocol A {
> func requiredFunction(a, b, c) -> T
> }
>
> that you could then extend
>
> extension A {
> func requiredFunction(a, b = somedefault, c) -> T;
> }
>
> as a declaration without an implementation?
I was thinking more that we could allow a fixed default on protocols where it makes sense to, for example:
protocol A {
func requiredFunction(a, b = somedefault, c) -> T
}
In this case all conforming types need to specify the same default for absolute consistency, but this may be a bit divergent from what the OP actually wants, I just mentioned it because it seemed a bit similar. This would come with the caveat that most of the time you don’t want to do this (as it could unnecessarily limit implementations) but it would mean that you know what the default is for every single conforming type.
Specifically for the OP though an attribute might make more sense, like:
struct Foo : A {
func requiredFunction(a, b = @public somedefault, c) -> T { … }
}
Here the default for b is explicitly declared as public, so would be exposed via documentation automatically; this would require that it isn’t derived from anything hidden (allowing this to be checked) and wouldn’t involve exposing every default value implicitly just for being on a public method as the OP was questioning.
Just some options anyway, since I don’t think exposing all defaults automatically is really viable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160613/5b01609a/attachment.html>
More information about the swift-evolution
mailing list