The constraint-first choice between []byte and []rune is exactly the right lesson. One additional boundary is that a rune is a Unicode code point, not necessarily a user-perceived character: combining marks and emoji sequences can still span multiple runes. For this ASCII problem []byte is both simpler and faster; for production text, the requirement should say whether it operates on bytes, code points, or grapheme clusters. That specification matters more than choosing the most Unicode-looking type.
Exactly. I like using this as a small API-design exercise: name the text unit in the function contract first, then choose the representation and tests. A few cases with combining accents and family emoji make the ambiguity obvious immediately.
Ahmet Özel
AI Engineer. Computer Vision, RAG and LLM agents.
The constraint-first choice between []byte and []rune is exactly the right lesson. One additional boundary is that a rune is a Unicode code point, not necessarily a user-perceived character: combining marks and emoji sequences can still span multiple runes. For this ASCII problem []byte is both simpler and faster; for production text, the requirement should say whether it operates on bytes, code points, or grapheme clusters. That specification matters more than choosing the most Unicode-looking type.