Live data from Hacker News

A bug that spoke Russian and crashed my app

imzaldih.com

21–22 of 22 posts

Re: A bug that spoke Russian and crashed my app

#21

Earlier quoted context omitted.

I agree. Locale.getLanguage() returns the language code. The specific Locale() constructor used in the code is documented as taking a parameter: "An ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to 8 characters in length. See the Locale class description about valid language values." I'd guess the app code lucked out on the string returned from getDisplayLanguage() getting mapped to the appropriat…

Would stronger typing help here? If I were to design those APIs, I'd maybe suggest a more opaque type called "LanguageCode" that is NOT a String and could not be returned from or passed as a String. Then getLanguage() could return a LanguageCode type, and the Locale() constructor could take the LanguageCode type as its parameter, and then tooling could enforce that you can't mix LanguageCode with String. Then, callin…

>Would stronger typing help here?

While we're not programmers, we can say with certainty that hitting the keys harder, does NOT change the behavior.

-Ops Team.

Re: A bug that spoke Russian and crashed my app

#22
post #18

Earlier quoted context omitted.

Kudos. We’ve all solved bugs with the wrong code. It was an interesting post and I found the unexpected secondary followup just as interesting. (Why did it work for, eg, Chinese, do you know?) See, I am not an Android developer either. I could have made the same mistake. To me it comes down to — why string types?

This is always the issue. It’s why Python and JavaScript are so terrible, and the cause of so many bugs, yet so readily available in apis and cicd pipelines. Why people insist on keep using strings instead of typesafe variants is beyond me

TypeScript is nice here because you can specify the specific strings you accept in a union. Eg. `unit: 'AC'|'DC'`
Post reply on HN