[swift-evolution] Carriage Return in Collection Array Literal Initializer

Kenny Leung kenny_leung at pobox.com
Mon Apr 25 11:25:39 CDT 2016


This is brilliant! If semicolons are optional, why not commas?

-Kenny


> On Apr 24, 2016, at 2:40 PM, Ross O'Brien via swift-evolution <swift-evolution at swift.org> wrote:
> 
> There was a discussion some time ago about making the comma of the last entry optional, because adding entries meant changing more than one line of code and this annoyed users of version control systems. This is an elegant approach to that problem.
> I don't know if it's a practical approach for the compiler, but if it is then I'm in favour.
> 
> On Sat, Apr 23, 2016 at 11:27 PM, Ivan Oparin via swift-evolution <swift-evolution at swift.org> wrote:
> Sometimes in is necessary to initialize a collection with a long list of items. Consider this example:
> 
> let dictionaryWithALotOfItems = ["someString0" : SomeFunctionality.0, "someString1" : SomeFunctionality.0, "someString2" : SomeFunctionality.0, "someString3" : SomeFunctionality.1, "someString4" : SomeFunctionality.1]
> 
> items are separated with a comma, and we can ommit it for the last item.
> 
> However, sometimes we deal with longer collections and we can make the code more readable by writing each item on it's own line:
> 
> let dictionaryWithALotOfItems = [
>     "someString0" : SomeFunctionality.0,
>     "someString1" : SomeFunctionality.0,
>     "someString2" : SomeFunctionality.0,
>     "someString3" : SomeFunctionality.1,
>     "someString4" : SomeFunctionality.1
> ]
> 
> now it looks much better except the comma in the end of line does not look natural
> 
> that is espessialy true for the line with a closure:
>     "someString5" : SomeFunctionality.2 { some functionality },
> 
> some closures are longer:
>     "someString6" : SomeFunctionality.3 {
>         some
>         long
>         closure
>         functionality
>     },
> 
> if Swift could treat carriage return in array literal initializer as a separation for the items, that would make some collections look cleaner:
> 
> let dictionaryWithALotOfItems = [
>     "someString0" : SomeFunctionality.0
>     "someString1" : SomeFunctionality.0
>     "someString2" : SomeFunctionality.0
>     "someString3" : SomeFunctionality.1
>     "someString4" : SomeFunctionality.1
> ]
> 
> just like a line without a semicolon looks better
> _______________________________________________
> 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