[swift-users] operators and external parameters

Ben Cohen ben_cohen at apple.com
Tue Jan 24 14:09:19 CST 2017


Dunno about good form, but the std lib universally employs the _-less variant if that helps:

https://github.com/apple/swift/blob/master/stdlib/public/core/Character.swift#L404

The _ certainly seem like clutter to me.

Same for subscripts, which have similar behavior.

> On Jan 24, 2017, at 10:14 AM, Ray Fix via swift-users <swift-users at swift.org> wrote:
> 
> 
> When defining an operator such as == you can implicitly specify external parameters:
> 
> struct Path: Equatable {
>     var value: String
> 
>     static func ==(lhs: Path, rhs: Path) -> Bool {
>         return lhs.value == rhs.value
>     }
> }
> 
> Is this considered okay, or is it bad form and it should really be defined:
> 
> 
> struct Path: Equatable {
>     var value: String
> 
>     static func ==(_ lhs: Path, _ rhs: Path) -> Bool {
>         return lhs.value == rhs.value
>     }
> }
> 
> Both seem to work fine in practice… 🤔  
> 
> Thank you!
> Ray
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170124/a63558bc/attachment.html>


More information about the swift-users mailing list