[swift-evolution] Colon vs. equals

Maximilian Hünenberger m.huenenberger at me.com
Fri Feb 5 18:49:30 CST 2016


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.

- Maximilian

> Am 06.02.2016 um 01:36 schrieb Andrew Bennett via swift-evolution <swift-evolution at swift.org>:
> 
> Interesting point, I guess ":" in dictionary literals is to make the syntax unambiguous.
> 
> This is currently valid swift:
> 
>     let x = [a = b]
> 
> Its type is: Array<Void>. It seems like the syntax is clearer if the delimiter isn't a valid operator.
> 
> Also there's a problem with default value syntax:
> 
>     func test(a: Int = 123)
> 
> This would be hard to read with only "=":
> 
>     func test(a = Int = 123)
> 
> Also if the default value was an operator:
> 
>     func test(a = Int -> Int = =)
> 
> Granted you could change the less commonly used default syntax, but it's probably syntactically easier to differentiate user-controller delimiters (assignment) and compiler-controller delimiters (:,). The example with assignment in an array illustrates this.
> 
> I do agree '@available' though, it seems like it should be ":"
> 
> =)
> 
> 
>> On Sat, Feb 6, 2016 at 10:27 AM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> This is perhaps a bit nitpicky, but I've noticed that Swift sometimes uses colon to separate names and values, and sometimes uses equals. It's vaguely maddening.
>> 
>> What do I mean? Well, our language has this:
>> 
>>         myFunc(foo, bar: baz)
>> 
>> But it also has:
>> 
>>         @available(iOS, introduced=7.0, deprecated=8.0)
>> 
>> You create a dictionary like this:
>> 
>>         let dict = ["key": "value"]
>> 
>> But you set it like this:
>> 
>>         dict["key"] = "value"
>> 
>> Is there some principle here? The @available case seems particularly strange to me, because those values read strongly like parameters to me.
>> 
>> --
>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160206/68abe976/attachment.html>


More information about the swift-evolution mailing list