Skip to content

[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

Merged
merged 4 commits into from
Dec 22, 2016

Conversation

natecook1000
Copy link
Member

  • 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
@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

Copy link
Contributor

@stephentyrone stephentyrone left a 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
Copy link
Contributor

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"?

Copy link
Member Author

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]
///
Copy link
Contributor

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.

Copy link
Member Author

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.

@airspeedswift airspeedswift self-requested a review December 15, 2016 19:48
@stephentyrone
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an -> a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- an
+ a

Copy link
Contributor

@Gankra Gankra left a 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
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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.
Copy link
Contributor

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)`
Copy link
Contributor

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"?

@natecook1000
Copy link
Member Author

@gankro Thanks for the flatMap feedback! I'm working on more comprehensive changes there since it shows up in a variety of places other than just the lazy collections. I'd like to merge this now essentially as a bug fix for the dangling "Equivalent to" in the discussion—I'll let you know when I have revised documentation for the rest.

@natecook1000
Copy link
Member Author

@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
Copy link
Member

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"

Copy link
Contributor

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])
Copy link
Collaborator

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?

Copy link
Member Author

@natecook1000 natecook1000 Dec 21, 2016

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.

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit 6805ecc into swiftlang:master Dec 22, 2016
@natecook1000 natecook1000 deleted the nc-fixes-06 branch December 22, 2016 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants