Thank you all for answers. I have a lot to do in next few weeks, after that I will go back to runes and think more about your answers.
Best, Kamil poniedziaĆek, 15 listopada 2021 o 21:52:27 UTC+1 imsach...@gmail.com napisaĆ(a): > On Tue, Nov 16, 2021 at 12:38 AM burak serdar <bse...@computer.org> wrote: > >> >> >> On Mon, Nov 15, 2021 at 11:00 AM Kamil Ziemian <kziem...@gmail.com> >> wrote: >> >>> Hello, >>> >>> I read quite a few blog posts, articles, listen to nice number to talks >>> about strings, runes and encoding in Go. I now reading Go Language Spec and >>> I just stuck in the section about runes. I mean, it isn't hard as itself, >>> but it raises to much questions to me. I decided that I need to learn more >>> about Unicode and UTF-8, so from today I'm reading Unicode Technical Site >>> (?), currently the Glossary (https://www.unicode.org/glossary/). *But I >>> can't understand one thing: when in practice you should use runes?* >> >> > *An example of data type "rune"* > *Lets say we want to retrieve 5th digit from an integer ( 1234567 )* > *Step 1 = convert an integer to string using "strconv.Itoa()" * > *Step 2 = convert that string to slice of rune using "rune"* > *Step 3 = retrieve 5th digit from slice of rune* > *Step 4 = convert the retrieved 5th digit to string* > > *here is an example* https://play.golang.org/p/M22Awjcu2-0 > > > > > > > > >> >>> My understanding at this moment is like that. Unicode assign every >>> symbol a number (at this moment I disregard normalization and any other >>> more advance stuff), rune is alias for int32 that stores integer >>> representation of this number. UTF-8 is variable size encoding using one or >>> more bytes to encode symbol and shouldn't and DOESN'T represent integer >>> value of symbols Unicode number. Virtues of UTF-8 are clear as how it >>> allows to save a space is clear to me, but I can't find a reason why I >>> should transform my text to runes? In Go stdlib there is a RuneReader >>> interface (?) so this reason must exists, but I just can't find anything. >>> Maybe it have something to do with sending information using internet? I >>> don't know, this is totally outside my humble knowledge. >>> >> >> In general, you should work with runes whenever you are working with text >> that is entered by humans, or text that will be read by humans. >> >> When you work with a string as a stream of bytes, then you either assume >> the string does not contain any bytes over 127, or you have to decode the >> UTF-8 string yourself. Working with runes eliminates both problems. >> >> >> >> >>> >>> You can say, that since I don't see a reason to use runes, I probably >>> shouldn't care about it. This is a valid point, but I want to know Go >>> reasonable well and constantly find code with runes which reason of >>> existence I don't understand (e.g. functions in stdlib that operates on >>> runes) is quite demoralising to me. >>> >>> Best >>> Kamil >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/f3dad0e1-cd25-4e33-a7f2-34e0118bf68an%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/golang-nuts/f3dad0e1-cd25-4e33-a7f2-34e0118bf68an%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqovfg9k9ALawv%2BC36_AxT0sbOb%2BEpcpKNO9r2kmg_T1nQ%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/golang-nuts/CAMV2Rqovfg9k9ALawv%2BC36_AxT0sbOb%2BEpcpKNO9r2kmg_T1nQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fdd0b249-b7ab-435a-a8f1-76b105bc8f83n%40googlegroups.com.