[swift-evolution] [SHORT Review] SE-0133: Rename `flatten()` to `joined()`
daniel at duan.org
Mon Jul 25 12:15:55 CDT 2016
> On Jul 24, 2016, at 11:10 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> * What is your evaluation of the proposal?
-1. I find the motivation section troubling. It’s simply an assertion that this “should” happen. From reading the rest of the proposed text as well as others reviews in support, I get the impression that combining flatten and joined results in an API that’s more “pleasing” to some because they do similar things.
IMO, the fact that they are similar is why we should *not* give them the same name. In summary, we would be trading 2 simpler APIs to a complex one. I don’t believe that’s a goal for Swift.
Both methods returns a corresponding Sequence, FlattenSequence and JoinedSequence. Creating a FlattenSequence is always lazy and has O(1) complexity, iterating over it is also a simple and efficient process. JoinedSequence on the other hand, has O(length_of_separator) complexity at init, and involves additional state juggling at iteration. Yes, if the separator is skipped, we could make the new `joined` behave exactly like `flatten`, and put its merits in the documentation, and warn them about the complexity difference, and explain whether/how it’s different to provide “” and nil when calling this on a string…
Hopefully, you can see why I’d rather give user `flatten` when that’s all they are looking for.
> * Is the problem being addressed significant enough to warrant a change to Swift?
> * Does this proposal fit well with the feel and direction of Swift?
Maybe. Less sometimes is good. But in this case it incurs a cost.
> * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
flatten is a well understood and commonly used operation in many PLs.
> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
read the proposal and posts on this list.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution