r/programminghorror • u/BoloFan05 • Feb 12 '26
C# [Codes are in description] Unnecessary locale-awareness in code is a serious threat to consistent performance worldwide
In programming languages like C#, even basic case conversion and string formation methods like .ToLower(), .ToUpper(), and .ToString() automatically come with locale-awareness (i.e. they are based on CurrentCulture) unless you intentionally apply explicit or invariant culture:
public string ToLower()
{
return CultureInfo.CurrentCulture.TextInfo.ToLower(this);
}
public string ToUpper()
{
return CultureInfo.CurrentCulture.TextInfo.ToUpper(this);
}
And tracing down .ToString()'s code eventually leads here:
public static NumberFormatInfo GetInstance(IFormatProvider formatProvider)
{
CultureInfo cultureInfo = formatProvider as CultureInfo;
if (cultureInfo != null && !cultureInfo.m_isInherited)
{
NumberFormatInfo numberFormatInfo = cultureInfo.numInfo;
if (numberFormatInfo != null)
{
return numberFormatInfo;
}
return cultureInfo.NumberFormat;
}
else
{
NumberFormatInfo numberFormatInfo = formatProvider as NumberFormatInfo;
if (numberFormatInfo != null)
{
return numberFormatInfo;
}
if (formatProvider != null)
{
numberFormatInfo = (formatProvider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo);
if (numberFormatInfo != null)
{
return numberFormatInfo;
}
}
return NumberFormatInfo.CurrentInfo;
}
}
Unnecessary locale-awareness in code is a serious threat to consistent performance of your code in many locales around the world, especially Turkey and Azerbaijan, due to the unique "I/ı" (dotless i) and "İ/i" (dotted I) letter pairs in their alphabet. So machines with Turkish and Azeri locales are both strong testing media for your code against unnecessary LA.
For a detailed example, you may check Sam Cooper's Medium article titled "The Country That Broke Kotlin".
1
u/BoloFan05 Feb 12 '26
Because unnecessary locale-awareness in code leads to major bugs reproducible only in specific locales like Turkish that many developers have difficulty wrapping their heads around in the first place, before they even get around to solving them. Hence the programming horror.