4 ms·
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
by ryandrake 3y ago
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, calling Locale's constructor with the return value from getDisplayLanguage() would produce an easy-to-find error.
- amne 3y agoThe API is the problem here. The method names in this case: getLanguageCode() and getLanguageName(), or getLanguageDisplayName() even, are much better names.
- xandrius 3y agoYep, having proper types instead of passing around strings would have prevented this.
- sonicanatidae 3y ago>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.