<div dir="ltr">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:<div><ol><li>Defining: `func max(x1 x1: Int, x2: Int = 0): Int` instead of `func max(x1 x1: Int, x2: Int = 0) -> Int`</li><li>Using: `let positive = max(x1 = -5)` instead of `let positive = max(x1: -5)`</li><li>Assigning: `var 0 -> x; 1 +-> x` instead of `var x = 0; x += 1`</li><li>Entries: `let dict = ["A" = 1, "B" = 2]` instead of `let dict = ["A" : 1, "B" : 2]`</li></ol><div>However the current syntax, whilst inconsistent, is OK and therefore not worth changing.</div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"> -- Howard.<br></div></div>
<br><div class="gmail_quote">On 10 February 2016 at 09:45, Oliver M via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><ul style="list-style-type:none" dir="ltr">
<li style="margin:0px;font-size:12px;font-family:Menlo">A brief observation regarding variable type declarations</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">I find the colon in variable type declarations a little odd.</li>
<li style="margin:0px;font-size:12px;font-family:Menlo">Consider the following:</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">var welcomeMessage: String</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">wouldn't this be cleaner simply written as</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">var welcomeMessage String</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">the documentation says to read the colon ':' as "of type" in such situations</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">but does the type "String" itself not imply 'of type String'</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">Consider the colon in a function declaration:</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">func sayHello(personName: String) {}</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">I would read the portion within the brackets as:</li>
<li style="margin:0px;font-size:12px;font-family:Menlo">parameter named personName takes value of type String (because you input values when calling functions)</li>
<li style="margin:0px;font-size:12px;font-family:Menlo">with the colon reading 'takes value' and "String" again reading 'of type String'</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">I find the colon ':' strongly associated with function input values, and with associations [key:value pairs etc]</li>
<li style="margin:0px;font-size:12px;font-family:Menlo">but variables…you don't input anything and they are not inherently associations.</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">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</li>
<li style="margin:0px;font-size:12px;font-family:Menlo;min-height:14px"><br></li>
<li style="margin:0px;font-size:12px;font-family:Menlo">var myIndex: "Int" </li>
<li style="margin:0px;font-size:12px;font-family:Menlo">myIndex = 0</li></ul></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>