[swift-evolution] Proposal: Remove the space before the colon in compiler-generated [Key : Value] dictionary types

Jacob Bandes-Storch jtbandes at gmail.com
Thu Jan 14 14:48:25 CST 2016


This sounds great, I look forward to it. The way interfaces & documentation
are formatted tend to act as an informal "style guide", so having them
match will be nice.

Jacob

On Thu, Jan 14, 2016 at 12:13 PM, Jack Lawrence via swift-evolution <
swift-evolution at swift.org> wrote:

> Hi Kevin,
>
> Thanks for bringing this to the list. I’m actually working on a slightly
> broader proposal to change the : style used by the decl printer to
> generally match more closely the style used in documentation, sample code,
> and the majority of the developer community. If you can hold off until
> tomorrow, I’ll send it out then.
>
> Xcode docsets and web docs use SourceKit to generate the declarations, so
> they would get automatically updated if we make these sort of changes to
> the compiler.
>
> Jack
> > On Jan 14, 2016, at 11:35 AM, Kevin Ballard via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > Whenever dictionaries are referenced using their shorthand syntax, they
> end up printed as `[Key : Value]`, with the space before the colon. This
> can be seen whenever the compiler emits the type of a dictionary (e.g.
> printing the imported interface of an obj-c header, printing the type of a
> result in the REPL, or printing the type of a declaration in LLDB with
> `type lookup`), as well as in the documentation.
> >
> > I think this looks weird. Dictionary type shorthand syntax is meant to
> look like a dictionary literal, and dictionary literals are almost
> universally written with no space before the colon. It makes sense to me
> for dictionary types to be written the same way, e.g. `[Key: Value]`. Not
> only does this look more like a dictionary literal, but I'd argue it also
> reduces confusion. Every other case that I can think of where you find
> space-colon-space syntax used is when declaring the bounds of a generic
> type parameter, or declaring the superclass/protocols of a type declaration
> (which is pretty similar to declaring the bounds). But in the syntax `[Key
> : Value]`, Value is not a bound on Key.
> >
> > To that end, I'd like to update the compiler to remove the space before
> the colon, and update any doc comments that reference dictionary shorthand
> syntax (though I'm not sure if there actually are any). A radar would also
> have to be filed to cover checking to make sure the Xcode docsets are
> updated, though I'm hoping the Xcode docsets use the compiler to generate
> the interface declarations already.
> >
> > Incidentally, it looks like the book already uses `[Key: Value]` syntax
> instead of `[Key : Value]` syntax. This means that whomever wrote the book
> believed `[Key: Value]` to be more sensible, and it also means that the
> first introduction most people have to Swift teaches them to use `[Key:
> Value]` instead of `[Key : Value]`.
> >
> > -Kevin Ballard
> > _______________________________________________
> > 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/20160114/b840b638/attachment.html>


More information about the swift-evolution mailing list