-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Various revisions and fixes for documentation #6311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
natecook1000
commented
Dec 15, 2016
- Fix wording for RandomAccessCollection
- Add note about array growth to reserveCapacity(_:)
- Reformat lazy flatMap discussions
- Improve Collection symbol consistency
- Fix wording for RandomAccessCollection - Add note about array growth to reserveCapacity(_:) - Reformat lazy flatMap discussions - Improve Collection symbol consistency
@swift-ci Please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, except for two small style questions inline. I have only reviewed Arrays.swift.gyb, as the other stuff is outside my sphere of expertise.
/// | ||
/// If you implement an custom data structure backed by an array that grows | ||
/// dynamically, naively calling the `reserveCapacity(_:)` method can lead | ||
/// to lower than expected performance. Arrays need to follow a geometric |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style question: "lower" or "worse"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"worse" is certainly clearer
/// array on each call. | ||
/// | ||
/// var values: [Int] = [0, 1, 2, 3] | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a standard method of marking code snippets that are showing "what not to do"? It would be nice to be explicit for someone skimming the text with a // don't do this
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really—there are cases where we mark that something won't compile, but haven't had cases quite like this. I added a comment.
Thanks Nate. I'm happy with the Array section. @airspeedswift please go ahead and approve once you review, if you like. |
/// Preserving an Array's Geometric Growth Strategy | ||
/// =============================================== | ||
/// | ||
/// If you implement an custom data structure backed by an array that grows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an -> a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- an
+ a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meta: is there any coherent rule for when docs should be duplicated from the "declaration" of a method and its various implementations in extensions?
/// Preserving an Array's Geometric Growth Strategy | ||
/// =============================================== | ||
/// | ||
/// If you implement an custom data structure backed by an array that grows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a
/// | ||
/// Use this method to receive only nonoptional values when your | ||
/// Use this method to receive a sequence of nonoptional values when your | ||
/// transformation produces an optional value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence reads very weird, and maybe implies something stronger than we actually guarantee. e.g. if your transform yields T??
we don't produce a Sequence<T>
, right?
/// - Parameter transform: A closure that accepts an element of this | ||
/// sequence as its argument and returns an optional value. | ||
/// - Parameter transform: A closure that accepts an element of this sequence | ||
/// as its argument and returns an optional value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curiosity: what's our policy on doc'ing arguments? For instance, this one is completely vacuous, describing the type of the argument in english. Without knowing our policy, I would be generally inclined to either omit the description, or provide an actually meaningful one.
/// Returns the concatenated results of mapping `transform` over | ||
/// `self`. Equivalent to | ||
/// Returns the concatenated results of mapping the given transformation over | ||
/// this collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're removing "concatenated" in some of these, and not others, any reasoning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only using "concatenated" when the result concatenates sequences/collections, not the optional unwrapping flatMap
/// | ||
/// self.map(transform).joined() | ||
/// Use this method to receive a single-level collection when your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Knowing what flatmap is, I get what's meant by "single-level", but if I didn't, it would be pretty meaningless?
This also has the same ambiguity T?? had, but with [[[T]]].
/// `limit` prevents offsetting beyond those bounds. | ||
/// The value passed as `n` must not offset `i` beyond `endIndex` or before | ||
/// `startIndex` for this collection, unless the index passed as `limit` | ||
/// prevents offsetting beyond those bounds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly preferred the old wording. Is this an actual rule we have?
@@ -269,9 +254,6 @@ where Index : Strideable, | |||
/// If `n` is negative, this is the same value as the result of `-n` calls | |||
/// to `index(before:)`. | |||
/// | |||
/// - Precondition: | |||
/// - If `n > 0`, `n <= self.distance(from: i, to: self.endIndex)` | |||
/// - If `n < 0`, `n >= self.distance(from: i, to: self.startIndex)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll admit that the above line is 100% more clear than this goop, but shouldn't the line above be listed as a "precondition"?
@gankro Thanks for the |
@swift-ci Please smoke test |
/// If you implement an custom data structure backed by an array that grows | ||
/// dynamically, naively calling the `reserveCapacity(_:)` method can lead | ||
/// to worse than expected performance. Arrays need to follow a geometric | ||
/// allocation pattern for appending elements to have amortized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to have" reads slightly oddly in the sentence for me, maybe "to achieve" or "to get"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to achieve" seems correct to me.
- Removed "see other" note from type discussion - Modified index(_:offsetBy...) to match other collections - Word choice in reserveCapacity(_:)
/// c[i] /= 5 | ||
/// i = c.index(after: i) | ||
/// } | ||
/// // c == MyFancyCollection([2, 4, 6, 8, 10]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for the elimination of this discussion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike other Indices
types, a CountableRange<_>
doesn't hold a reference to the collection, so that part of the discussion isn't accurate. It still shows up on the protocol requirement and the unconstrained indices
implementations.
@swift-ci Please smoke test and merge |