<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Default parameters are in my opinion an implementation detail and should be always handled by the conforming type. What can be done here is only declare the 4th method in the protocol and create a protocol extension with default forwarding.</div><div><br>On 04 Dec 2015, at 17:31, Ben <<a href="mailto:ben_cocoa_dev_list@yahoo.co.uk">ben_cocoa_dev_list@yahoo.co.uk</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii">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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=T04LrBojaExXAX0mv-2F2MMtIB9rMFpWjvqf12Pj37IVJ-2FsU837QZ6P4QGPieGfVoMxOwRl-2B-2Bg9Es-2BxNNVtZeXHOqZuQJ-2Bv0B7ohE-2FvLSOGiB9CrlDNyobNQ8p1B7-2F-2BylOSvyuZe7fdyIba7BssFiAr69MFcNiIxKtbG4fulekDUfR5JBCiEkE8CFduV8B9LbQQV8BOSJU2HaGi28344V4F6tyHkRRni1gsgHuVI30iis-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>