Day 36: Wifi Woes and Language Matching
🐍 Mood: Having extremely unstable wifi and using a ridiculously long ethernet cable across my entire house aka a giant trip cord.
🎵 Soundtrack: Songs from the Arc of Life
🔌 Wifi Woes
Initially my wifi would work for 5 minutes before needing to be restarted. Only my work computer was having issues. Then it needed to be restarted every 3 minutes. Then 30 seconds. Restarting my computer multiple times did not fix it. Restarting the router did not fix it. Nothing fixed it. Eventually I got the reeeeeeeeeeeally long ethernet cable out.
🩺 Gopls Tests
It turns out my mega code actions feature breaks some existing tests. I starred at them for awhile and I was going to dig deeper into it, but then I got distracted by a github issue.
🇫🇷🇬🇧 Language Matching
Someone opened an issue where go is matching the wrong language. This piqued my interest because back on day 10 I had done a little digging into language matching.
I had fun digging into this bug and this is what I found out so far. I also added the following to the issue as a comment.
Some background Context
- Match calls
getBest
. getBest
loops through all of the provided tags. It keeps track of abest
option. It callsbest.update
for each provided tag. If the tag is a better match than the current best, then it updatesbest
.
For the working as expected case with desired, _, err := language.ParseAcceptLanguage("en-GB;q=1.0, fr-DE;q=0.9, fr-CA;q=0.8")
- Because English is only in the list of tags once, pin for
en-GB
is true. - This sets
m.LanguagePin
to true here. en-GB
is initially made the best option because it is first andbeaten
is set to true here.- Then the loop continues and
best.update
is called for the next tags one at a time. - Because
m.LanguagePin
is true, every tag afteren-GB
returns fromupdate
here and does not replaceen-GB
asbest
. - Thus
en-GB
is returned as the best match.
For the buggy case with desired, _, err := language.ParseAcceptLanguage("en-GB;q=1.0, fr;q=0.9, fr-CA;q=0.8, en-DE;q=0.7")
- Because English is only in the list of tags twice, pin for
en-GB
is false. - This sets
m.LanguagePin
to false here. en-GB
is initially made the best option because it is first andbeaten
is set to true here.- Then the loop continues and
best.update
is called for the next tagfr-DE
. - Since
m.LanguagePin
is false, it does NOT return fromupdate
here like in the example above. - This tag makes it into a tie breaker with
en-GB
.fr-DE
ends up winning the tie-breaker here. - Thus
fr-DE
is returned as the best match.
❓ My main open question is: Where do the weights come into play? And why didn’t the weights prevent French from beating English?
🎉😱 I’m listed as a contributor!
After submitting my comment mentioned above I saw a tag I never saw before. I am listed as a contributor! :D :D :D :D :D