# StringIndex idea (Julia 2.0)

**URL:** <https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185>\
**Category:** Internals & Design\
**Tags:** strings, indexing\
**Created:** [December 5, 2023, 8:23pm UTC](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185 "2023-12-05T20:23:43Z")\
**Posts on this page:** 1\
**Showing post:** 32

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 5, 2024, 1:00pm UTC](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185/32 "2024-02-05T13:00:30Z")

</div>

> [@mnemnion](#):
>
> I wanted to follow up on this a bit. The obvious disadvantage of working with strings properly is that many operations go from O(1) to O(n). This isn’t so bad by itself, but its consequence is: many string algorithms of interest (most?) are O(n) _given O(1) indexing_, so they become O(n²), and _that_ is bad news.

I disagree with your premise that random codepoint indexing is “working with strings properly”. String algorithms that involve random access should be operating on codeunits (= bytes in UTF-8), not codepoints (`Char`s), and **codeunits already provide O(1) access**.

So far, in all the discussions of strings in Julia, to my recollection there has not been a single example of a practical string algorithm that requires random-access _codepoint_ indexing (as opposed to a “pointer” to a previously traversed location, as in a search result).

The discussions on this thread about making the current string (codeunit) indices opaque and adding other index types have mostly been about making things more intuitive for new users, and preventing bugs due to mis-use of `s[i+1]` instead of `s[nextind(s, i)]` and similar. Not about an algorithmic need for fast random character indexing.

(AFAIK, _no_ mainstream programming language other than Python3 tries to guarantee O(1) random codepoint access for its default string type, and Python3’s [idiosyncratic approach comes with a lot of disadvantages](https://discourse.julialang.org/t/string-indices-byte-indexing-feels-wrong/107164/17).)

---

_[View the full topic](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185)._
