[swift-evolution] [Pre-proposal] Replace [Foo] With CollectionType

Xiaodi Wu xiaodi.wu at gmail.com
Sat May 28 14:16:43 CDT 2016


I couldn't disagree more. Generic programming is a far more advanced
concept than arrays and dictionaries, and learners should be able to use
them without contending with angle brackets they don't understand.

Fundamentally, even for an experienced user of the language, working with
Collections and Sequences requires more consideration than working with
arrays. It's not just a matter of how these things are spelled. It seems
like you want to punish users who don't have the time or inclination to
genericize their algorithms by making them write more, in the hopes that if
you make working with arrays difficult enough, people will switch to
generic containers. That's bonkers.

On Sat, May 28, 2016 at 14:38 Haravikk via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On 27 May 2016, at 15:31, plx via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>   protocol Sequence {
>
>     typealias of<E> == S: Self where S.Iterator.Element == E
>   }
>
>   // sequence-accepting variant
>   func doSomething<S:Sequence.of<Foo>>(values: S) { … }
>
>
> This is a nice alternative; would it actually need to be declared in the
> angle brackets? Could it be done as:
>
> func doSomething(values:Sequence.of<Foo>) { … }
>
> As long as it would work the same as a generic declaration this could be a
> good way to do it, either that or a SequenceOf type alias as mentioned.
>
>
> Still, I kind of feel like we need to do something with the array type
> shorthand, but I wonder if perhaps we could just get rid of it altogether,
> to prevent its use entirely? i.e- all instances of [Foo] can be replaced
> with Array<Foo>, but we would encourage the use of
> Sequence.of/SequenceOf/Collection.of/CollectionOf first wherever possible.
>
> As more types become available that are ArrayLiteralConvertible it seems
> like we should discourage restriction of a parameter to Array except when a
> developer explicitly chooses it. This problem will come up with the
> Dictionary type shorthand as well if Swift gets some kind of Map protocol
> to abstract it, and we don’t even have a Set-specific syntax so it seems
> like it may be fairer to remove these shorthands.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160528/c3a6e3e8/attachment.html>


More information about the swift-evolution mailing list