11
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ 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 \$\endgroup\$
    – Martin Ender Mod
    Commented Jan 2, 2016 at 23:24
  • \$\begingroup\$ Related \$\endgroup\$ Commented Jan 2, 2016 at 23:27
  • 5
    \$\begingroup\$ @MartinBüttner, locales also change things like default date format strings, date parsing, separators in floating point numbers, etc. \$\endgroup\$ Commented Jan 2, 2016 at 23:31
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – FUZxxl
    Commented Jan 3, 2016 at 2:31
  • \$\begingroup\$ @FUZxxl If a user does that, just don't upvote those posts. ¯\_(ツ)_/¯ \$\endgroup\$
    – Alex A. Mod
    Commented Jan 3, 2016 at 3:52
  • 1
    \$\begingroup\$ If a user is creative enough to do that, reward it with some votes! \$\endgroup\$ Commented Jun 21, 2017 at 15:59

5 Answers 5

22
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ And no penalty? Then this is equal to the answer by Alex A. \$\endgroup\$
    – FUZxxl
    Commented Jan 2, 2016 at 23:22
  • 1
    \$\begingroup\$ No penalty. Alex said that you shouldn't need to specify... \$\endgroup\$
    – user46167
    Commented Jan 2, 2016 at 23:23
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jan 4, 2016 at 22:35
  • \$\begingroup\$ 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). \$\endgroup\$ Commented Sep 9, 2016 at 22:23
5
\$\begingroup\$

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.

\$\endgroup\$
0
-4
\$\begingroup\$

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.

\$\endgroup\$
-5
\$\begingroup\$

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Why is en_US.UTF-8 more "standard" than C or POSIX? \$\endgroup\$ Commented Jun 21, 2017 at 16:00
-6
\$\begingroup\$

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.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – user46167
    Commented Jan 2, 2016 at 23:15
  • \$\begingroup\$ @BlockCoder1392 The intent is that code that depends on locale must pay for that while not paying as strongly as with the other approach. \$\endgroup\$
    – FUZxxl
    Commented Jan 2, 2016 at 23:17
  • \$\begingroup\$ While I agree with this answer in principle, it's rather platform dependent, and I don't see a nice way to fix that. \$\endgroup\$ Commented Jan 2, 2016 at 23:30
  • 5
    \$\begingroup\$ -e is free in Perl answers. \$\endgroup\$
    – Dennis Mod
    Commented Jan 3, 2016 at 0:03
  • \$\begingroup\$ @Dennis That used to be different. \$\endgroup\$
    – FUZxxl
    Commented Jan 3, 2016 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .