▲ | frollogaston 4 days ago | |||||||
I know this isn't the biggest thing, but it's funny how even simple questions have complicated answers in Swift, ex https://stackoverflow.com/questions/39677330/how-does-string... | ||||||||
▲ | JimDabell 4 days ago | parent | next [-] | |||||||
Strings and Unicode are a lot more complicated than they first appear. I like the way this article puts it: > Swift’s string implementation goes to heroic efforts to be as Unicode-correct as possible. […] This is great for correctness, but it comes at a price, mostly in terms of unfamiliarity; if you’re used to manipulating strings with integer indices in other languages, Swift’s design will seem unwieldy at first, leaving you wondering. > It’s not that other languages don’t have Unicode-correct APIs at all — most do. For instance, NSString has the enumerateSubstrings method that can be used to walk through a string by grapheme clusters. But defaults matter; Swift’s priority is to do the correct thing by default. > Strings in Swift are very different than their counterparts in almost all other mainstream programming languages. When you’re used to strings effectively being arrays of code units, it’ll take a while to switch your mindset to Swift’s approach of prioritizing Unicode correctness over simplicity. > Ultimately, we think Swift makes the right choice. Unicode text is much more complicated than what those other languages pretend it is. In the long run, the time savings from avoided bugs you’d otherwise have written will probably outweigh the time it takes to unlearn integer indexing. — https://oleb.net/blog/2017/11/swift-4-strings/ I’d encourage you to read that entire article before describing strings as simple. | ||||||||
| ||||||||
▲ | JustExAWS 4 days ago | parent | prev [-] | |||||||
Someone hasn’t programmed on Windows… https://www.reddit.com/r/cpp_questions/comments/10pvfia/look... |