Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More information about the string type in documentation #1269

Open
telemachus opened this issue Jun 11, 2022 · 0 comments
Open

More information about the string type in documentation #1269

telemachus opened this issue Jun 11, 2022 · 0 comments

Comments

@telemachus
Copy link

telemachus commented Jun 11, 2022

Proposal

Please consider adding more information about strings in the documentation.

The current example uses "Bob" as a string, and this simplifies things since it is all ASCII.

However, consider the following:

name := "Hello, 世界"
println name.len      // 13 (This will likely surprise many new users, especially non-programmers.)
println name[0]       // 72 (This will likely surprise many new users, especially non-programmers.)
println name[7]       // 228 (This will likely confuse a lot of people, including programmers.)
println name[7:13]    // 世界 (13 will confuse many.)
println name[7:10]    // 世 (10 will confuse many.)
println name[7:9]     // � (Many users will try something like this and be confused by the result.)

It would be great if the documentation said more about the complex interplay between strings, runes, and Unicode.

Background

I was reading the documentation, and I was confused. The strings tutorial has the same problem because it also uses only ASCII characters.

In particular, I was initially confused by this:

println name[0]   // 66

I realized quickly that this was a decimal representation of an ASCII character, but I wondered two things. First, why does a single string index return a numeric representation of a character rather than the character itself? (Compare, e.g., Python: a = 'Bob'; print(a[0]) # 'B'.) Second, what happens to that numeric representation if the string is outside the ASCII range?

This all makes reasonable sense if you come from Go and are familiar with strings, runes, and Unicode there, but for newcomers it will likely be confusing.

Workarounds

I'm not aware of any workaround right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants