<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi list,<div class=""><br class=""></div><div class="">I propose that methods defined in protocols should accept default arguments. This could help remove the need for method families where only one parameter is essential, but others are often used.</div><div class=""><br class=""></div><div class="">For example:</div><div class=""><br class=""></div><div class="">protocol Datastore {</div><div class=""> func executeQuery(query: String)</div><div class=""> func executeQuery(query: String, usingParameters: [Any])</div><div class=""> func executeQuery(query: String, usingParameters: [Any], logType: LogType)</div><div class=""> func executeQuery(query: String, usingParameters: [Any], logType: LogType, completionHandler:ClosureOfSomeSort)</div><div class="">}</div><div class=""><br class=""></div><div class="">Where typically the implementing object funnels the first three methods through to the final, more verbose method.</div><div class=""><br class=""></div><div class="">This could be shortened to:</div><div class=""><br class=""></div><div class=""><div class="">protocol Database {</div><div class=""> func executeQuery(query: String, usingParameters: [Any] = [], logType: LogType = .NotLogged completionHandler:ClosureOfSomeSort? = nil)</div><div class="">}</div></div><div class=""><br class=""></div><div class="">Advantages:</div><div class="">- Only one method to implement</div><div class="">- Less to document, less cluttered interface</div><div class="">- Prevent objects adopting the protocol from using different default values</div><div class="">- Prevent objects from implementing similar methods in the family differently - fewer code paths to inspect, less confusion over behaviour since no argument values are hidden</div><div class=""><br class=""></div><div class="">This fits in well with the parameters section of the Swift API design page: <a href="https://swift.org/documentation/api-design-guidelines.html#parameters" class="">https://swift.org/documentation/api-design-guidelines.html#parameters</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">What do you think?</div><div class=""><br class=""></div><div class="">Regards,</div><div class=""><br class=""></div><div class="">Ben Barnett</div></body></html>