[swift-evolution] [RFC] "Library Evolution Support in Swift ('Resilience')"
Goffredo Marocchi
panajev at gmail.com
Tue Feb 9 01:59:57 CST 2016
Sent from my iPhone
On 9 Feb 2016, at 05:32, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> It seems to me that using a default parameter means you don’t care about its value. If you explicitly want a certain value, and especially if you’re *depending* on a certain value, it would be best to supply that value explicitly. Using the default is saying “eh, do whatever you think is best."
>
> Sometimes it means you don't care about the value; sometimes it means that the parameters are rarely used and the defaults are fine for you. For instance, if you're using the variant of `NSString.compare` with no options, you probably care very much that you're getting the default "minimal frills" behavior and your search covers the entire string. You would be very surprised and probably rather annoyed if a future OS version made your code compare only the first ten characters case-insensitively.
Conscious of infuriating lots of non unit testing fanatics, this does make a good case for writing your own unit tests against the API's you commonly use too ;).
>
> If a library wants to support "just do what you think is best", it should explicitly model that, either by having a value like `.Automatic` or `nil` as the default, or by providing a separate method. `NSString`, for example, takes the latter option in `localizedStandardCompare`.
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list