[swift-evolution] an observation on colons in variable type declarations

Adrian Kashivskyy adrian.kashivskyy at me.com
Wed Feb 10 03:32:47 CST 2016


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 at 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 at swift.org <mailto:swift-evolution at 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 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>
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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


More information about the swift-evolution mailing list