[swift-evolution] [Pitch] Option parameters (potential resilience advantages)

Joe Groff jgroff at apple.com
Mon Dec 28 14:04:15 CST 2015


> On Dec 28, 2015, at 11:46 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Dec 28, 2015, at 1:39 PM, Stephen Celis <stephen.celis at gmail.com> wrote:
>> 
>> I'm not sure I understand the use case. Aren't these optimizations that could be better handled by the compiler? Do we really want to provide hints like these manually in our own libraries? Instead of `value: Int? = nil`, why not `value: Int = 42`?
> 
> I agree that part of this is simply an optimization.  The part that was interesting enough that I thought it is worth sharing is that it could improve resilience in a way that a default value does not allow.
> 
> That said, it is not a “proposal”.  I’m not sure whether it is really worth considering or not.  But I think it is interesting enough to toss out to the community and see what the response is.

You can provide resilience with a non-optional parameter by making the default argument the result of calling a resilient function (or evaluating a resilient property):

@availability(x.y)
internal func defaultForFoo() -> Int { return 941 }

public func foo(value: Int = defaultForFoo()) { }

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151228/34a4f9ff/attachment.html>


More information about the swift-evolution mailing list