Source code " : " guidelines


(Kostiantyn Koval) #1

Hi Swift team,

Is there a perfect style for ":" when declaring a Type?
I have seen 2 styles in Swift source code.

extension Deck : Equatable
extension Deck: Equatable

Is there any guideline for it or both are acceptable?

Best Regards,
Kostiantyn


(Paul Schifferer) #2

My personal preference is to put a space on both sides of the colon when it’s used for declaration or extension:

class SomeClass : SomeProtocol {
var name : String
}

and a space only after it’s used for providing a value (as in a function parameter):

object.callSomething(value: v)

···

--
Paul

On December 5, 2015 at 10:24:40, Kostiantyn Koval (konstantin.koval1@gmail.com) wrote:

Hi Swift team,

Is there a perfect style for ":" when declaring a Type?
I have seen 2 styles in Swift source code.

extension Deck : Equatable
extension Deck: Equatable

Is there any guideline for it or both are acceptable?

Best Regards,
Kostiantyn
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


#3

I believe Apple style prefers no space to the left:

https://twitter.com/_jackhl/status/646723367576276992

Stephen

···

On Dec 5, 2015, at 1:43 PM, Paul Schifferer <paul@schifferers.net> wrote:

My personal preference is to put a space on both sides of the colon when it’s used for declaration or extension:

class SomeClass : SomeProtocol {
  var name : String
}

and a space only after it’s used for providing a value (as in a function parameter):

object.callSomething(value: v)

--
Paul

On December 5, 2015 at 10:24:40, Kostiantyn Koval (konstantin.koval1@gmail.com <mailto:konstantin.koval1@gmail.com>) wrote:

Hi Swift team,

Is there a perfect style for ":" when declaring a Type?
I have seen 2 styles in Swift source code.

extension Deck : Equatable
extension Deck: Equatable

Is there any guideline for it or both are acceptable?

Best Regards,
Kostiantyn
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users


(Kostiantyn Koval) #4

This is code from https://github.com/apple/swift-package-manager
public enum Error: ErrorType {
}

extension Package : Equatable {
}

I see that in most palaces Apple prefer not having the space on the left side.
But it wan't sure if it's ok to make a PR for that :slight_smile:

Best Regards,
Kostiantyn

···

On 05 Dec 2015, at 19:48, Stephen Celis <stephen.celis@gmail.com> wrote:

I believe Apple style prefers no space to the left:

https://twitter.com/_jackhl/status/646723367576276992

Stephen

On Dec 5, 2015, at 1:43 PM, Paul Schifferer <paul@schifferers.net <mailto:paul@schifferers.net>> wrote:

My personal preference is to put a space on both sides of the colon when it’s used for declaration or extension:

class SomeClass : SomeProtocol {
  var name : String
}

and a space only after it’s used for providing a value (as in a function parameter):

object.callSomething(value: v)

--
Paul

On December 5, 2015 at 10:24:40, Kostiantyn Koval (konstantin.koval1@gmail.com <mailto:konstantin.koval1@gmail.com>) wrote:

Hi Swift team,

Is there a perfect style for ":" when declaring a Type?
I have seen 2 styles in Swift source code.

extension Deck : Equatable
extension Deck: Equatable

Is there any guideline for it or both are acceptable?

Best Regards,
Kostiantyn
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users


(Dave Abrahams) #5

That's the style we use in the Swift standard library, FWIW.

···

on Sat Dec 05 2015, Paul Schifferer <paul-AT-schifferers.net> wrote:

My personal preference is to put a space on both sides of the colon when it’s used for declaration or extension:

class SomeClass : SomeProtocol {
var name : String
}

and a space only after it’s used for providing a value (as in a function parameter):

object.callSomething(value: v)

--
Dave


(Roshan) #6

To me, no space to the left makes more sense. It conveys a sense of
belonging that is similar to variable declarations.

extension Deck: Equatable indicates that the Deck class is Equatable in the
same way var a: Int indicates that a is Int...

···

On Sun, Dec 6, 2015 at 12:30 AM, Kostiantyn Koval < konstantin.koval1@gmail.com> wrote:

This is code from https://github.com/apple/swift-package-manager
public enum Error: ErrorType {
}

extension Package : Equatable {
}

I see that in most palaces Apple prefer not having the space on the left
side.
But it wan't sure if it's ok to make a PR for that :slight_smile:

Best Regards,
Kostiantyn

On 05 Dec 2015, at 19:48, Stephen Celis <stephen.celis@gmail.com> wrote:

I believe Apple style prefers no space to the left:

https://twitter.com/_jackhl/status/646723367576276992

Stephen

On Dec 5, 2015, at 1:43 PM, Paul Schifferer <paul@schifferers.net> wrote:

My personal preference is to put a space on both sides of the colon when
it’s used for declaration or extension:

class SomeClass : SomeProtocol {
  var name : String
}

and a space only after it’s used for providing a value (as in a function
parameter):

object.callSomething(value: v)

--
Paul

On December 5, 2015 at 10:24:40, Kostiantyn Koval ( > konstantin.koval1@gmail.com) wrote:

Hi Swift team,

Is there a perfect style for ":" when declaring a Type?
I have seen 2 styles in Swift source code.

extension Deck : Equatable
extension Deck: Equatable

Is there any guideline for it or both are acceptable?

Best Regards,
Kostiantyn
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Warm regards
Roshan