[swift-evolution] an observation on colons in variable type declarations
Howard Lovatt
howard.lovatt at gmail.com
Tue Feb 9 18:28:01 CST 2016
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 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
> 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/eb7c9544/attachment.html>
More information about the swift-evolution
mailing list