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


(Lily Ballard) #1

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


(Jack Lawrence) #2

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(David Sweeris) #3

I use " : " (space on both sides) for everything except type annotations & generic constraints. Didn't realize I was doing it wrong.

···

On Jan 14, 2016, at 11:35, Kevin Ballard via swift-evolution <swift-evolution@swift.org> wrote:

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.


(Jacob Bandes-Storch) #4

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@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@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@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Erica Sadun) #5

Jack, if you could share a style guide, it would be widely beneficial. I'm constantly referring to your tweets for guidance, for example: https://twitter.com/_jackhl/status/646480946619805697

-- E

···

On Jan 14, 2016, at 1:13 PM, Jack Lawrence via swift-evolution <swift-evolution@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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Charles Srstka) #6

I’ve tried it both ways, but I’ve found that the I prefer the space on both sides of the colon for dictionary literals. The symmetry makes it easier to read, and to distinguish the elements from each other. All IMO, of course.

Charles

···

On Jan 14, 2016, at 3:38 PM, David Sweeris via swift-evolution <swift-evolution@swift.org> wrote:

I use " : " (space on both sides) for everything except type annotations & generic constraints. Didn't realize I was doing it wrong.

On Jan 14, 2016, at 11:35, Kevin Ballard via swift-evolution <swift-evolution@swift.org> wrote:

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.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Howard Lovatt) #7

I am not particularly fussed by the spacing, but I do tend to use a space
either side for dictionaries and for ?: and for the rest no space before.

···

On Friday, 15 January 2016, David Sweeris via swift-evolution < swift-evolution@swift.org> wrote:

I use " : " (space on both sides) for everything except type annotations &
generic constraints. Didn't realize I was doing it wrong.

> On Jan 14, 2016, at 11:35, Kevin Ballard via swift-evolution < > swift-evolution@swift.org <javascript:;>> wrote:
>
> 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.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <javascript:;>
https://lists.swift.org/mailman/listinfo/swift-evolution

--
  -- Howard.