swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.76k stars 162 forks source link

Clarify the Types of Protocol Requirements in the Language Guide #244

Open tadbyt opened 10 months ago

tadbyt commented 10 months ago

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/protocols https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations#Protocol-Subscript-Declaration https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations#Protocol-Associated-Type-Declaration

Description

Add the following sentence to the end of the first paragraph in the introduction of the Protocols section:

Requirements may be provided for properties, methods, mutating methods, initializers, failable initializers, subscripts, and associated types.

Motivation

The division of The Swift Programming Language into its two major components, Language Guide and Language Reference, sometimes leaves holes in one or the other. In particular, sections of the Language Guide often enumerate most but not all significant aspects of a feature. While the missing aspect is detailed in the Language Reference, a reader may not think to look there as they may not realize the aspect exists. Providing a sentence such as this makes the reader aware of the missing aspects and provides a nudge to check the appropriate Language Reference section for it.

Alternatives Considered

Adding brief subsections for subscript and associated type requirements that would provide both some discussion and an example of each.

Adding the following note instead of, or in addition to, the proposed change just prior to the Protocols As Types subsection:

Note: For a discussion of subscript requirements, see [link to the Protocol Subscript Declaration subsection]. For a discussion of associated type requirements, see [link to the Protocol Associated Type Declaration subsection].