an observation on colons in variable type declarations


(Oliver M) #1

- A brief observation regarding variable type declarations

···

-

   - I find the colon in variable type declarations a little odd.
   - Consider the following:
   -

   - var welcomeMessage: String
   -

   - wouldn't this be cleaner simply written as
   -

   - var welcomeMessage String
   -

   -

   - the documentation says to read the colon ':' as "of type" in such situations
   -

   - but does the type "String" itself not imply 'of type String'
   -

   -

   -

   - Consider the colon in a function declaration:
   -

   - func sayHello(personName: String) {}
   -

   - I would read the portion within the brackets as:
   - parameter named personName takes value of type String (because you input values when calling functions)
   - with the colon reading 'takes value' and "String" again reading 'of type String'
   -

   -

   -

   - I find the colon ':' strongly associated with function input values, and with associations [key:value pairs etc]
   - but variables…you don't input anything and they are not inherently associations.
   -

   -

   - When coding half asleep I find myself compelled to input a value wherever I see a ':' and I can see myself typing something really really silly
   -

   - var myIndex: "Int"
   - myIndex = 0


(Howard Lovatt) #2

I also find it odd that -> is used for return types instead of a :. My
favourite would be for = to be used for assigning to argument labels,
initialization of lets, and dictionary entries, : used for types, and ->
used for assignment to vars. IE:

   1. Defining: `func max(x1 x1: Int, x2: Int = 0): Int` instead of `func
   max(x1 x1: Int, x2: Int = 0) -> Int`
   2. Using: `let positive = max(x1 = -5)` instead of `let positive =
   max(x1: -5)`
   3. Assigning: `var 0 -> x; 1 +-> x` instead of `var x = 0; x += 1`
   4. Entries: `let dict = ["A" = 1, "B" = 2]` instead of `let dict = ["A"
   : 1, "B" : 2]`

However the current syntax, whilst inconsistent, is OK and therefore not
worth changing.

  -- Howard.

···

On 10 February 2016 at 09:45, Oliver M via swift-evolution < swift-evolution@swift.org> wrote:

   - A brief observation regarding variable type declarations
   -
   - I find the colon in variable type declarations a little odd.
   - Consider the following:
   -
   - var welcomeMessage: String
   -
   - wouldn't this be cleaner simply written as
   -
   - var welcomeMessage String
   -
   -
   - the documentation says to read the colon ':' as "of type" in such
   situations
   -
   - but does the type "String" itself not imply 'of type String'
   -
   -
   -
   - Consider the colon in a function declaration:
   -
   - func sayHello(personName: String) {}
   -
   - I would read the portion within the brackets as:
   - parameter named personName takes value of type String (because you
   input values when calling functions)
   - with the colon reading 'takes value' and "String" again reading 'of
   type String'
   -
   -
   -
   - I find the colon ':' strongly associated with function input values,
   and with associations [key:value pairs etc]
   - but variables…you don't input anything and they are not inherently
   associations.
   -
   -
   - When coding half asleep I find myself compelled to input a value
   wherever I see a ':' and I can see myself typing something really really
   silly
   -
   - var myIndex: "Int"
   - myIndex = 0

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


(Taras Zakharko) #3

It really depends on what you are used to. Swift notation comes from mathematics and formal computer science. You seem to be more used to the Fortran/ALGOL/C syntax. Personally, I prefer the Swift way, its cleaner and less confusing to me.

At any rate, I don’t think there is a valid reason to reconsider this design aspect of the language.

···

On 09 Feb 2016, at 23:45, Oliver M via swift-evolution <swift-evolution@swift.org> wrote:

A brief observation regarding variable type declarations

I find the colon in variable type declarations a little odd.
Consider the following:

var welcomeMessage: String

wouldn't this be cleaner simply written as

var welcomeMessage String

the documentation says to read the colon ':' as "of type" in such situations

but does the type "String" itself not imply 'of type String'

Consider the colon in a function declaration:

func sayHello(personName: String) {}

I would read the portion within the brackets as:
parameter named personName takes value of type String (because you input values when calling functions)
with the colon reading 'takes value' and "String" again reading 'of type String'

I find the colon ':' strongly associated with function input values, and with associations [key:value pairs etc]
but variables…you don't input anything and they are not inherently associations.

When coding half asleep I find myself compelled to input a value wherever I see a ':' and I can see myself typing something really really silly

var myIndex: "Int"
myIndex = 0
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jessy) #4

However the current syntax, whilst inconsistent, is OK and therefore not worth changing.

Subscripts use arrows, despite them allowing setters. Properties use a colon instead of arrow. That at least needs to be standardized.

Personally, I see no need for the arrow we have today. It’s not even a real arrow character and so looks antiquated.

https://forums.developer.apple.com/thread/16592


(Adrian Kashivskyy) #5

Howard, there is an ongoing discussion about using equal sign instead of a colon in dictionary literals.

Anyway, I'm -1 on all of this. Colons explicitly and successfully separate name from its type. What happens if you type

let String String

in your scenario? How can one distinguish what's what?

Besides, Oliver and Howard, your only argument is that "you find it odd". To convince me (and many others, I presume), you'd need to provide a stronger argument.

Pozdrawiam – Regards,
Adrian Kashivskyy

···

Wiadomość napisana przez Howard Lovatt via swift-evolution <swift-evolution@swift.org> w dniu 10.02.2016, o godz. 01:28:

I also find it odd that -> is used for return types instead of a :. My favourite would be for = to be used for assigning to argument labels, initialization of lets, and dictionary entries, : used for types, and -> used for assignment to vars. IE:
Defining: `func max(x1 x1: Int, x2: Int = 0): Int` instead of `func max(x1 x1: Int, x2: Int = 0) -> Int`
Using: `let positive = max(x1 = -5)` instead of `let positive = max(x1: -5)`
Assigning: `var 0 -> x; 1 +-> x` instead of `var x = 0; x += 1`
Entries: `let dict = ["A" = 1, "B" = 2]` instead of `let dict = ["A" : 1, "B" : 2]`
However the current syntax, whilst inconsistent, is OK and therefore not worth changing.

  -- Howard.

On 10 February 2016 at 09:45, Oliver M via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
A brief observation regarding variable type declarations

I find the colon in variable type declarations a little odd.
Consider the following:

var welcomeMessage: String

wouldn't this be cleaner simply written as

var welcomeMessage String

the documentation says to read the colon ':' as "of type" in such situations

but does the type "String" itself not imply 'of type String'

Consider the colon in a function declaration:

func sayHello(personName: String) {}

I would read the portion within the brackets as:
parameter named personName takes value of type String (because you input values when calling functions)
with the colon reading 'takes value' and "String" again reading 'of type String'

I find the colon ':' strongly associated with function input values, and with associations [key:value pairs etc]
but variables…you don't input anything and they are not inherently associations.

When coding half asleep I find myself compelled to input a value wherever I see a ':' and I can see myself typing something really really silly

var myIndex: "Int"
myIndex = 0

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

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


(Jean-Denis Muys) #6

I read the colon a bit like “corresponds to”, which (with some stretch) fits how it is used.

Defining: `func max(x1 x1: Int, x2: Int = 0): Int` instead of `func max(x1 x1: Int, x2: Int = 0) -> Int`

I prefer the arrow, that really suggests something is returned, to be handled later. I would prefer a real arrow though, in these Unicode times, rather than “dash”-“greater than” (which could be accepted as a digraph maybe)

Using: `let positive = max(x1 = -5)` instead of `let positive = max(x1: -5)`

Here, “=“ meaning assignment works very well, better than the colon probably

Assigning: `var 0 -> x; 1 +-> x` instead of `var x = 0; x += 1`

This is totally wrong to me. It is at complete odd with “let a = 5”. Assignment is written with receiver on the left, in Swift as in the vast majority of languages. Reversing that is gratuitous and very difficult to read. The second case, with the strange “stopped arrow” +-> which looks very much like |-> i even worse.

Entries: `let dict = ["A" = 1, "B" = 2]` instead of `let dict = ["A" : 1, "B" : 2]`

So you mean you assign the integer 2 to the string “A”? Let me die in horror.

Standard math notation uses the equal sign for both assignment and comparison (it can also be argued that in maths, there is no assignment, only comparison, and the phrase “let x=3” actually means “let’s consider the case where x=3”).
Pascal used to replace = with := out of fear of confusing = with comparison. C decided to alter the comparison rather than the assignment.

Choosing yet another meaning for “=“, writing “String” = 1 is really an anathema to my eyes.

Jean-Denis

···

On 10 Feb 2016, at 01:28, Howard Lovatt via swift-evolution <swift-evolution@swift.org> wrote:

I also find it odd that -> is used for return types instead of a :. My favourite would be for = to be used for assigning to argument labels, initialization of lets, and dictionary entries, : used for types, and -> used for assignment to vars. IE:
Defining: `func max(x1 x1: Int, x2: Int = 0): Int` instead of `func max(x1 x1: Int, x2: Int = 0) -> Int`
Using: `let positive = max(x1 = -5)` instead of `let positive = max(x1: -5)`
Assigning: `var 0 -> x; 1 +-> x` instead of `var x = 0; x += 1`
Entries: `let dict = ["A" = 1, "B" = 2]` instead of `let dict = ["A" : 1, "B" : 2]`
However the current syntax, whilst inconsistent, is OK and therefore not worth changing.

  -- Howard.

On 10 February 2016 at 09:45, Oliver M via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
A brief observation regarding variable type declarations

I find the colon in variable type declarations a little odd.
Consider the following:

var welcomeMessage: String

wouldn't this be cleaner simply written as

var welcomeMessage String

the documentation says to read the colon ':' as "of type" in such situations

but does the type "String" itself not imply 'of type String'

Consider the colon in a function declaration:

func sayHello(personName: String) {}

I would read the portion within the brackets as:
parameter named personName takes value of type String (because you input values when calling functions)
with the colon reading 'takes value' and "String" again reading 'of type String'

I find the colon ':' strongly associated with function input values, and with associations [key:value pairs etc]
but variables…you don't input anything and they are not inherently associations.

When coding half asleep I find myself compelled to input a value wherever I see a ':' and I can see myself typing something really really silly

var myIndex: "Int"
myIndex = 0

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

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


(Ilya Belenkiy) #7

+1 on all points made by Taras

···

On Wed, Feb 10, 2016 at 12:44 PM Taras Zakharko via swift-evolution < swift-evolution@swift.org> wrote:

It really depends on what you are used to. Swift notation comes from
mathematics and formal computer science. You seem to be more used to the
Fortran/ALGOL/C syntax. Personally, I prefer the Swift way, its cleaner and
less confusing to me.

At any rate, I don’t think there is a valid reason to reconsider this
design aspect of the language.

On 09 Feb 2016, at 23:45, Oliver M via swift-evolution < > swift-evolution@swift.org> wrote:

   - A brief observation regarding variable type declarations
   -
   - I find the colon in variable type declarations a little odd.
   - Consider the following:
   -
   - var welcomeMessage: String
   -
   - wouldn't this be cleaner simply written as
   -
   - var welcomeMessage String
   -
   -
   - the documentation says to read the colon ':' as "of type" in such
   situations
   -
   - but does the type "String" itself not imply 'of type String'
   -
   -
   -
   - Consider the colon in a function declaration:
   -
   - func sayHello(personName: String) {}
   -
   - I would read the portion within the brackets as:
   - parameter named personName takes value of type String (because you
   input values when calling functions)
   - with the colon reading 'takes value' and "String" again reading 'of
   type String'
   -
   -
   -
   - I find the colon ':' strongly associated with function input values,
   and with associations [key:value pairs etc]
   - but variables…you don't input anything and they are not inherently
   associations.
   -
   -
   - When coding half asleep I find myself compelled to input a value
   wherever I see a ':' and I can see myself typing something really really
   silly
   -
   - var myIndex: "Int"
   - myIndex = 0

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

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