[swift-evolution] [Discussion] Design guideline rule for `:`

Haravikk swift-evolution at haravikk.me
Wed Jun 22 08:04:02 CDT 2016


This is an interesting thing to consider, as the current auto-complete seems to favour whitespace on both sides, but I actually use it differently depending upon context.

For specifying type I use no whitespace, but for inheritance/conformance I use whitespace on both sides, so for me it's:

	protocol A : B {}
	func foo<T:A>() -> T { … }
	var value:Type
	[hey1:value1, key2:value2]

Not really able to give an objective reason why though, it just feels more natural to me this way, I suppose because the separation is useless on a type declaration to avoid creating noise around the type name itself, but everywhere else I just prefer the more compact form.

> On 22 Jun 2016, at 12:40, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Should there be a design guideline rule for colons : in Swift?
> 
> I see people doing things like this:
> 
> protocol A : B {}
> 
> // VS.
> 
> protocol A: B {}
> func foo<T : A>() -> T { … }
> 
> // VS.
> 
> func foo<T: A>() -> T { … }
> var value : Type
> 
> // VS.
> 
> var value: Type
> [key1 : value1, key2 : value2]
> 
> // VS.
> 
> [key1: value1, key2: value2]
> I prefer the second style, where there is no whitespace between lhs and the : symbol and there is also a whitespace after :. Example: something: somethingElse
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

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


More information about the swift-evolution mailing list