<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 14, 2016 at 5:41 PM, Michael Savich via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><span>Back in Swift 1.0, subscripting a String was easy, you could just use subscripting in a very Python like way. But now, things are a bit more complicated. I recognize why we need syntax like str.startIndex.advancedBy(x) but it has its downsides. Namely, it makes things hard on beginners. If one of Swift&#39;s goals is to make it a great first language, this syntax fights that. Imagine having to explain Unicode and character size to an 8 year old. This is doubly problematic because String manipulation is one of the first things new coders might want to do. </span></div><div><span><br></span></div><div><span>What about having an InternalString subclass that only supports one encoding, allowing it to be subscripted with Ints? The idea is that an InternalString is for Strings that are more or less hard coded into the app. Dictionary keys, enum raw values, that kind of stuff. This also has the added benefit of forcing the programmer to think about what the String is being used for. Is it user facing? Or is it just for internal use? And of course, it makes code dealing with String manipulation much more concise and readable.</span></div><div><span><br></span></div><div>It follows that something like this would need to be entered as a literal to make it as easy as using String. One way would be to make all String literals InternalStrings, but that sounds far too drastic. Maybe appending an exclamation point like &quot;this&quot;! Or even just wrapping the whole thing in exclamation marks like !&quot;this&quot;! Of course, we could go old school and write it like @&quot;this&quot; …That last one is a joke.</div><div style="direction:inherit"><br></div><div style="direction:inherit">I&#39;ll be the first to admit I&#39;m way in over my head here, so I&#39;m very open to suggestions and criticism. Thanks!</div></div></blockquote><div><br></div><div>I can sympathize, but this is tricky.</div><div><br></div><div>Fundamentally, if it&#39;s going to be a learning and teaching issue, then this &quot;easy&quot; string should be the default. That is to say, if I write `var a = &quot;Hello, world!&quot;`, then `a` should be inferred to be of type InternalString or EasyString, whatever you want to call it.</div><div><br></div><div>But, we also want Swift to support Unicode by default, and we want that support to do things The Right Way(TM) by default. In other words, a user should not have to reach for a special type in order to handle arbitrary strings correctly, and I should be able to reassign `a = &quot;你好&quot;` and have things work as expected. So, we also can&#39;t have the &quot;easy&quot; string type be the default...</div><div><br></div><div>I can&#39;t think of a way to square that circle.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div style="direction:inherit"><br></div><span></span><span>Sent from my iPad</span></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>