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

Oliver M selectedfordeletion at yahoo.com
Tue Feb 9 16:45:46 CST 2016


   
   - 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160209/f78666fa/attachment.html>


More information about the swift-evolution mailing list