[swift-evolution] Pitch: Improved Swift pointers
xiaodi.wu at gmail.com
Wed Aug 9 21:52:55 CDT 2017
On Wed, Aug 9, 2017 at 8:22 PM, Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:
> On Jul 19, 2017, at 11:21 AM, Taylor Swift via swift-evolution <
> swift-evolution at swift.org> wrote:
> What about `value:`?
> `ptr.initialize(value: value)`
> `ptr.initialize(value: value, count: 13)`
> `ptr.initialize(as: UInt16.self, at: 0, value: value, count: 13)`
> Doesn't read as a sentence. Consider how "initialize to 3" sounds
> different from "initialize value 3".
> Personally, I'd go with:
> ptr.initialize(to: value)
> ptr.initialize(to: value, repeatCount: 3)
> (Or just `repeat`/`repeating` if you don't feel like you need the word
> "count" to disambiguate.)
Per Swift API naming guidelines, initializers don't have to read as
sentences IIRC, and I'd be inclined to grant a function named
`initialize(_:)` the same courtesy.
For arrays, `repeating:` labels the repeating value, not the number of
times it repeats, and the analogous labels here would indeed be
`ptr.initialize(repeating: value, count: 3)`. I agree with the observations
above that `repeating` looks weird if the default and most common use is 1,
though; `value` is fine, I guess--or the Swiftism `pointee`?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution