# Should locale be explicitly specified?

Triggered by this comment.

Some answers assume a specific locale. For example this answer assumes a locale of en_US.UTF-8. If the default locale on a given system uses a different encoding, then the answer becomes invalid. In order to make it valid, extra code to set the LC environment variables needs to be added with the effect of increasing the CG score.

@FUZxxl and I had an interesting discussion on this. I think we'd both like to see a community consensus on this one.

• I don't know much about system locales. Could someone clarify for me how this is different from this question? meta.codegolf.stackexchange.com/q/5878/8478 – Martin Ender Jan 2 '16 at 23:24
• Related – Peter Taylor Jan 2 '16 at 23:27
• @MartinBüttner, locales also change things like default date format strings, date parsing, separators in floating point numbers, etc. – Peter Taylor Jan 2 '16 at 23:31
• Another POV is, a user could define a family of locales and encode parts of his program into the locale. Locale contains information and not counting locale towards the program score is a nice way to hide some bytes of code, something I don't agree with. – FUZxxl Jan 3 '16 at 2:31
• @FUZxxl If a user does that, just don't upvote those posts. ¯\_(ツ)_/¯ – Alex A. Jan 3 '16 at 3:52
• If a user is creative enough to do that, reward it with some votes! – Toby Speight Jun 21 '17 at 15:59

# If it requires a specific locale, specify

I think this is the best solution. For example, if the code requires a locale of en_US.UTF-8 then you must specify in the answer. This is similar to how we specify encodings if it requires a specific encoding, e.g. Windows-1252.

• And no penalty? Then this is equal to the answer by Alex A. – FUZxxl Jan 2 '16 at 23:22
• No penalty. Alex said that you shouldn't need to specify... – ev3commander Jan 2 '16 at 23:23
• I think this is probably the right answer. However there are times when it is not known to the answerer that a specific locale is required. In that case, are answerers required to test all submissions in all locales, just to be sure? – Digital Trauma Jan 4 '16 at 22:35
• Would like to add that some languages/frameworks (C#/.NET, because it's all I know) depend on the local for everything, int.Parse("1.1") depends on where you are in the world - there's no opting in, only opting out (e.g. Invariant Culture) - any program that uses any formatting or parsing method would require a specific locale. If there were any issue, I'd suggest the Invariant Culture as the assumed default, because it is never going to change. (It's pretty much en-US as far as I'm aware). – VisualMelon Sep 9 '16 at 22:23

## No need to specify locale

I think this is splitting hairs. If you test a submission and it doesn't work due to locale settings, try English UTF-8. If that doesn't work, ask the poster of the submission.

If the submission requires a certain locale, the poster should mention this as a courtesy to those who wish to test the submission. However, there should be no penalty for this.

# en_US.UTF-8 is the default locale

Most mainstream operating systems will have US English (and thus en_US.UTF-8) as their defaults at install time. Users will have to select something else if they want a different encoding.

Code may depend on the locale being en_US.UTF-8 and only that locale without penalty.

• Why is en_US.UTF-8 more "standard" than C or POSIX? – Toby Speight Jun 21 '17 at 16:00

# C is the default locale

The standard (and only) locale as defined by IEEE 1003.1 (POSIX) and ISO 9899:2011 (C11) is the C locale (or the equivalent POSIX locale). Code that requires a different locale must explicitly set one.

## Add byte count of locale

Answers that depend on locale in any way except for the C locale must add to their score the length of the locale name (e.g. en_US.UTF-8 counts as 11 characters). This is similar to how perl answers add one character if the -e flag is passed to the interpreter.

• This doesn't make sense--- would you add 9 chars just because the encoding is UTF-16LE? Also, it would give an advantage to locales with shorter names – ev3commander Jan 2 '16 at 23:15
• @BlockCoder1392 The intent is that code that depends on locale must pay for that while not paying as strongly as with the other approach. – FUZxxl Jan 2 '16 at 23:17
• While I agree with this answer in principle, it's rather platform dependent, and I don't see a nice way to fix that. – Peter Taylor Jan 2 '16 at 23:30
• -e is free in Perl answers. – Dennis Jan 3 '16 at 0:03
• @Dennis That used to be different. – FUZxxl Jan 3 '16 at 11:54