[swift-evolution] Colon vs. equals
Thorsten Seitz
tseitz42 at icloud.com
Sat Feb 6 14:22:05 CST 2016
> Am 06.02.2016 um 12:18 schrieb Haravikk via swift-evolution <swift-evolution at swift.org>:
>
> +1 for changing attributes to using colons, as it would make them read more like a function call (albeit one with slightly different rules).
>
> -1 though for changing dictionary literals; personally I think the colon syntax is a lot clearer, especially when the literal is being assigned, as it means there is only a single, clear assignment.
I agree with Haravikk on both points.
-Thorsten
> Regarding assigning new values to a dictionary though, I wonder if we might extend the literal syntax to modifying an existing dictionary? For example, I might do something like:
>
> myDictionary[“foo”: 1, “bar”: 2] // Add/set new values for foo and bar
>
> As this could be a neater way to replace:
>
> myDictionary[“foo”] = 1
> myDictionary[“bar”] = 2
>
> Essentially we’d have a subscript for setting a single value, and one for setting a dictionary, without the need to do:
>
> myDictionary[[“foo”: 1, “bar”: 2]]
>
> Since the second braces should be redundant I think. This would allow developers to avoid the use of assignments with dictionaries if they wish.
>
>> On 6 Feb 2016, at 01:22, Maximilian Hünenberger via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> Inline
>>
>> Am 06.02.2016 um 02:07 schrieb Brent Royal-Gordon <brent at architechies.com>:
>>
>>>> If ":" should be replaced by "=" than only at the call site to make it more consistent with variable declaration and initialization:
>>>>
>>>> myFunc(number = 4, string = 7)
>>>>
>>>> func myFunc(number: Int, string: String) {}
>>>>
>>>> Although writing "=" instead of ":" in methods in 1.5 years Swift and over 20 years Objective-C would be a huge change.
>>>
>>> To be clear, I like colon in parameter lists; I don't see passing a parameter as setting something.
>>
>> I cannot say whether I like ":" in parameter lists or if I'm just used to them...
>>
>> Though setting parameters doesn't seem wrong to me. In fact value types get copied to a new parameter which is declared in the function signature.
>>
>>> I suppose mainly what I'd like is for attributes to change:
>>>
>>> @available(iOS, introduced: 7.0, deprecated: 8.0)
>>>
>>> And *possibly* for dictionary literals to change:
>>>
>>> let dict = ["key" = "value"] // Also, the shorthand syntax would be [String = String]
>>>
>>> Although dictionary literals seem like a relatively high-impact change compared to its value.
>>
>> Yeah that would be true and also ":" in dictionaries reads to me like a "map this value to another one". So it would rather be "=>" than "=" which reads like an assignment to the left "<=".
>>
>> - Maximilian
>>
>>>
>>> --
>>> Brent Royal-Gordon
>>> Architechies
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> 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
More information about the swift-evolution
mailing list