🦃 Mood: November! My favorite month!

🎵 Soundtrack: Reading Music

📚 Reading Github Issues

Lots of issues about the compiler and generics, including one where Filippo Valsorda(!!!) says it was his first time writing generic code! Good to know I’m not the only one who hasn’t tried it yet.

🧺 Collating

After last week’s investigation into language sorting, I decided to see if there were any other open issues related to x/text/language. This one about “incorrect sorting of Slovak words” caught my eye. The issue is about how the collate function does not sort Slovak words correctly (specifically the letters with accents). My first thought was: wow that must suck. Imagine you are a frontend developer and you just want to list whatever (songs, states, names, anything) in alphabetical order. But, oh no! Go sorts them wrong! Even when you specify which language you are using.

I started poking around the collate pkg. I was trying to understand what was going on, but there were no examples! Something I can fix! So I spent most of my day learning about collate by writing examples for all of the functions.

Like this one:

func ExampleNew() {
	letters := []string{"ä", "å", "ö", "o", "a"}

	ec := collate.New(language.English)
	ec.SortStrings(letters)
	fmt.Printf("English Sorting: %q\n", letters)

	sc := collate.New(language.Swedish)
	sc.SortStrings(letters)
	fmt.Printf("Swedish Sorting: %q\n", letters)

	numbers := []string{"0", "11", "01", "2", "3", "23"}

	ec.SortStrings(numbers)
	fmt.Printf("Alphabetic Sorting: %q\n", numbers)

	nc := collate.New(language.English, collate.Numeric)
	nc.SortStrings(numbers)
	fmt.Printf("Numeric Sorting: %q\n", numbers)

	// Output:
	// English Sorting: ["a" "å" "ä" "o" "ö"]
	// Swedish Sorting: ["a" "o" "å" "ä" "ö"]
	// Alphabetic Sorting: ["0" "01" "11" "2" "23" "3"]
	// Numeric Sorting: ["0" "01" "2" "3" "11" "23"]
}

I ran a local copy of the go pkgsite to make sure that they showed up correctly, and I ended up submitting a little PR there as well.

♺ Generics

🎥 At the end of my day I watched my first talk about generics “GopherCon 2020: Robert Griesemer - Typing [Generic] Go”. I haven’t gotten a chance to play around with generics myself yet, but hopefully soon!