Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coding in non-ASCII languages

Tags:

c#

.net

unicode

Alright, I found this strikingly odd to me but in C#, you can actually write your source code in a different language. I've wrote an example source code in Korean to illustrate my point:

namespace 대한민국 {
    public class 학생 {
        public string 이름 { get; private set; }
        public string 좌우명 { get; private set; }

        public 학생(string 이름, string 좌우명) {
            this.이름 = 이름;
            this.좌우명 = 좌우명;
        }
    }
    public class 대학교 {
        private List<학생> 재학생목록 = new List<학생>();

        public void 입학(학생 입학생) {
            재학생목록.Add(입학생);
        }

        public void 재학생출력() {
            foreach (학생 선택된학생 in 재학생목록) {
                Console.WriteLine("이름: {0}", 선택된학생.이름);
                Console.WriteLine("좌우명: {0}", 선택된학생.좌우명);
            }
        }
    }
    public class 프로그램 {
        static void Main(string[] args) {
            대학교 스쿨오브헬 = new 대학교();
            스쿨오브헬.입학(new 학생("전땅끄", "본인은 단돈 29만원과 땅끄로 이 신성하고 거룩한 국가의 민주주의를 발전시켰소"));
            스쿨오브헬.입학(new 학생("이피카츄", "여러분 이거 다 거짓말인거 아시죠!!!"));
            스쿨오브헬.입학(new 학생("빵상아줌마", "빵빵 똥똥똥똥 땅땅 따라라라라~~~"));

            스쿨오브헬.재학생출력();
        }
    }
}

The above code compiles and gives you a valid output.

With the exception of keywords, you could actually write your source code in languages other than English. Of course, this is highly impractical and nobody would do this.

My question is the following:

  • Is this a C# feature or a Visual Studio feature? (I couldn't get a similar program to work in C++ under Visual Studio 2010)
  • What is the performance impact? (I would readily assume almost none, but wasn't sure if they did any kind of crazy conversion for allowing non-ASCII characters for coding)
  • What was the reason for implementing this feature?
like image 959
l46kok Avatar asked Feb 20 '23 00:02

l46kok


1 Answers

1: it is in the C# language specification, so: C#

2: none whatsoever; parsers don't really care much whether something is Fred vs 프로그램; neither is significant to the compiler

3: because not all developers speak English (or: latin languages) as their primary language. It could well be that 프로그램 expresses the intention of the class very readily and meaningfully for the developers working on that project

like image 135
Marc Gravell Avatar answered Feb 27 '23 14:02

Marc Gravell