<div><div dir="auto">It seems to me that some of these concerns could be fixed by returning ArraySlice instead of Array on popFirst(). Then you’d have similar performance expectations and explicit copying like with String / Substring.</div><div dir="auto"><br></div><div dir="auto">Geordie</div><div dir="auto"><br></div><br><div class="gmail_quote"><div>Elia Cereda via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; schrieb am Mo. 18. Sep. 2017 um 11:12:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>NSMutableArray does provide O(1) insertion and removal from the start and the end of the array (<a href="http://ciechanowski.me/blog/2014/03/05/exposing-nsmutablearray/" target="_blank">http://ciechanowski.me/blog/2014/03/05/exposing-nsmutablearray/</a>). </div><div><br></div><div>I think the reason Swift doesn&#39;t use this design is because it stores the data in a contiguous block of memory. </div></div><div dir="auto"><div><br><div><div>Elia Cereda</div></div></div></div><div dir="auto"><div><br>Il giorno 18 set 2017, alle ore 04:48, Jon Shier via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; ha scritto:<br><br></div><blockquote type="cite"><div><span class="m_-6190485580496396870Apple-tab-span" style="white-space:pre-wrap">        </span>Yes, it seems to fly in the face of protocols as they exist in Swift at the moment. Given the inability of protocols to guarantee performance characteristics, breaking conformant types like this seems like a bad way to try and fulfill a separate axis of concern. Wouldn’t a better idea be to move things like popFirst(), and other methods requiring O(1) performance, to a separate protocol? I’m also pretty sure it’s possible to implement popFirst in O(1) for an Array, but Swift’s Array isn&#39;t generally very fast, at least compared to C / C++.<div><br></div><div><br></div><div><br></div><div>Jon<br><div><br><blockquote type="cite"><div>On Sep 17, 2017, at 9:45 PM, Rick Mann via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-6190485580496396870Apple-interchange-newline"><div><blockquote type="cite" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-6190485580496396870Apple-interchange-newline">On Sep 17, 2017, at 03:25 , Quinn The Eskimo! via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br><br><br>On 15 Sep 2017, at 21:35, Vladimir.S via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br><br><blockquote type="cite">… for me it is very strange decision to disallow a method because it is &#39;expensive&#39;.<br></blockquote><br>That’s pretty normal for Swift standard library protocols, which define not just the behaviour of the routine but expected performance.  `popFirst()` is expected to be O(1) and that’s not possible with `Array`.<br><br>The rationale behind this decision is, I believe, related to generic algorithms.  If I write generic code that uses `popFirst()`, I can only guarantee the complexity of my code if I can rely on `popFirst()` being O(1).  If someone implements `popFirst()` as O(n), my generic algorithm might go from O(n^2) to O(n^3), which is quite a change.<br><br>On 16 Sep 2017, at 01:44, Rick Mann via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br><br><blockquote type="cite">Is the compiler looking at the name &quot;pop&quot; and adding additional constraints (and then spewing a bogus error message)?<br></blockquote><br>I’m not sure what’s going on here mechanically but, yes, the error message is bogus.  This is exactly what SR-5515 is talking about.<br><br>If I were in your shoes I’d call this method something other than `popFirst()`.  This falls under my standard “if you change the semantics, change the name” rule.  Your implementation of `popFirst()` doesn’t conform to the semantics of `popFirst()` — it’s O(n) because `removeFirst()` is O(n) — and thus you want to avoid calling it `popFirst()`.<br></blockquote><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">All right, I&#39;m happy to change the name to &quot;safeRemoveFirst()&quot;, but I&#39;m a bit irritated that there&#39;s an implicit performance constraint based on the name alone, without any obvious decorator syntax.</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">--<span class="m_-6190485580496396870Apple-converted-space"> </span></span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Rick Mann</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:rmann@latencyzero.com" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">rmann@latencyzero.com</a><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-users mailing list</span><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-users@swift.org" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-users@swift.org</a><br style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-users" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a></div></blockquote></div><br></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></div></blockquote></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div>