r/ProgrammingLanguages • u/funcieq • May 23 '26
Discussion How to implement String?
Currently, String in my language is just value and length because it's a temporary solution, And as the language has developed, I am now able to rewrite a lot just for it, so I want to make a decent String in my language. So my question is, which String concept annoys you the least?
47
Upvotes
View all comments
Show parent comment
7
u/prehensilemullet May 24 '26
Qt has a nifty alternative,
QStringis mutable but uses copy-on-write (if there are any other references to the string data, it’s copied before write so the other references still point to the same data). This way, there’s less need for separate builder APIs for performance’s sake.Using
QStringas a map key does have a mutation risk though. But since it’s C++ you can useconst QStringto make it immutable.