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
3
u/Karyo_Ten May 23 '26
I would do
or more explicitly
This way you don't have to allocate zero length strings and you can pass the string by registers.
And NUL terminator that isn't counted in length so you can pass the pointer to C APIs.
And you can build a Rune abstraction on top for UTF-8 but it's a rabbit hole.