[swift-evolution] [RFC] "Library Evolution Support in Swift ('Resilience')"

Brent Royal-Gordon brent at architechies.com
Mon Feb 8 23:32:46 CST 2016

> 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.

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

More information about the swift-evolution mailing list