8

English is not my native language. I would like to use non-English characters in my code, for instance: "ç, ã, é ..."

Is it a bad practice to use those characters for classes, variable or method declarations?

I'm not asking what characters are technically available in c#, My question is whether or not it is a good idea.

Danii-Sh
  • 447
  • 1
  • 4
  • 18
Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
  • 5
    C# source is unicode - yes, [you can use non-English characters](https://msdn.microsoft.com/en-us/library/aa664670.aspx). Bear in mind it might make it difficult for people with different keyboard layouts to maintain your code, though. – Blorgbeard Aug 16 '16 at 23:53
  • Possible duplicate of [What characters are allowed in C# class name?](http://stackoverflow.com/questions/950616/what-characters-are-allowed-in-c-sharp-class-name) – J... Aug 16 '16 at 23:54
  • 1
    See also : http://stackoverflow.com/q/3370546/327083 – J... Aug 16 '16 at 23:55
  • 1
    To those voting to close: The "duplicate" question is a technical question. Daniel is not asking the technical question. – Cort Ammon Aug 17 '16 at 00:02
  • @CortAmmon If you take away the technical part of the question, all that's left is subjective and opinion-based and, therefore, also off-topic. – J... Aug 17 '16 at 00:05
  • @J... where do questions like that go? Programmers.SE? – Cort Ammon Aug 17 '16 at 00:07
  • @CortAmmon Wouldn't think so there either. see : http://meta.stackoverflow.com/q/265928/327083 http://meta.stackoverflow.com/q/312021/327083 http://meta.stackexchange.com/q/142353/222049 , etc – J... Aug 17 '16 at 00:13
  • @J... I really understand your point. based on this, where questions like this should go? – Daniel Santos Aug 17 '16 at 00:28
  • 2
    @Blorgbeard: yes, the C# code is Unicode and therefore you can use special characters - but just wait until you want to use e.g. Git or something else that again thinks ASCII-7 is the way to go ..... I'd just simply *always* avoid national and special characters when coding - sooner or later, those will cause trouble .... – marc_s Aug 17 '16 at 04:39
  • Since you can't reall get anything else: My __opinion__: __Yes__, bad practice! – TaW Aug 17 '16 at 06:51
  • When you want to use such characters, it also implies that you use non-English names for classes, functions, properties, etc. Who will understand that? International teams can't use it. From this point of view, it is a really bad idea. Better stick to English. – Bernhard Hiller Aug 17 '16 at 07:31

3 Answers3

9

There's no technical issues with using non-English characters. C# allows a very large number of Unicode symbols in variable names. The real question is whether or not it is a good idea.

To answer that, you really have to ask yourself a question of "who is my audience?" If your code will only be looked at by French speakers typing on a French layout keyboard, ç is probably a very valid character. However, if you intend your code to be modified by others whose keyboard layout is not French, you may find that that symbol is very hard for them to type. This will mean that, if they want to use your variable name, they'll have to cut/paste it in place because they can't type it directly. This would be a death sentence for any development.

So figure out who your audience is, and limit yourself to their keyboard layout.

Cort Ammon
  • 10,221
  • 31
  • 45
6

It's supported. See here: http://rosettacode.org/wiki/Unicode_variable_names#C.23

Whether it's bad practice or not, it's hard to tell. If it works, it works. Personally, I'd just choose a language all the possible contributors understand.

HaukurHaf
  • 13,522
  • 5
  • 44
  • 59
1

I just tried the 3 characters you listed there and it compiled when I used them as variable names, so I assume that means they won't cause issues in your code.

Cody
  • 2,643
  • 2
  • 10
  • 24
  • 1
    Software isn't a science experiment; there are very well defined rules - trial and error is a bad habit. Consulting the documentation is all you need to do to know for sure. – J... Aug 17 '16 at 10:18