[swift-evolution] My personal beef with leading-dot syntax

Evan Maloney emaloney at gilt.com
Wed Apr 6 17:13:13 CDT 2016


> Agreed.  Let me ask the question differently: what value does the 
> leading `.` provide to the user of the language?


I find the leading-dot syntax to be very useful; it's a pretty clear shorthand that I'm not referencing something at global scope.

Here's a common example from our codebase:

completion(.Failed(.wrap(error)))

The completion function takes an enum value of type DataTransactionResult, of which .Failed is one case. The .Failed case takes an associated value of type DataTransactionError, which has a static function called wrap() that accepts an ErrorType and returns a DataTransactionError containing it.

Although .Failed is being used here in the common enum shorthand style, being able to very quickly determine that wrap() is not a global function is helpful. Without the leading dot, some context disappears:

completion(Failed(wrap(error)))

Now, it's a lot harder to tell what I'm dealing with.

What is 'Failed'? Is it a class with an initializer that we're passing the result of wrap(error) to? Or is it an enum case with an associated type? Further, what's wrap()? A function in the global scope? Sure looks like it!

If we got rid of the shorthand altogether, we end up with something much more verbose:

completion(DataTransactionResult.Failed(DataTransactionError.wrap(error)))

Yes, it's more explicit, but I would not necessarily argue that it's easier to read.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160406/5e4ef29b/attachment.html>


More information about the swift-evolution mailing list