Should source code be saved in UTF-8 format

后端 未结 5 1439
醉酒成梦
醉酒成梦 2020-12-03 02:56

How important is it to save your source code in UTF-8 format?

Eclipse on Windows uses CP1252 character encoding by default. The CP1251 format means non UTF-8 charact

5条回答
  •  死守一世寂寞
    2020-12-03 03:06

    What is your goal? Balance your needs against the pros and cons of this choice.

    UTF-8 Pros

    • allows use of all character literals without \uHHHH escaping

    UTF-8 Cons

    • using non-ASCII character literals without \uHHHH increases risk of character corruption
      • font and keyboard issues can arise
      • need to document and enforce use of UTF-8 in all tools (editors, compilers build scripts, diff tools)
    • beware the byte order mark

    ASCII Pros

    • character/byte mappings are shared by a wide range of encodings
      • makes source files very portable
      • often obviates the need for specifying encoding meta-data (since the files would be identical if they were re-encoded as UTF-8, Windows-1252, ISO 8859-1 and most things short of UTF-16 and/or EBCDIC)

    ASCII Cons

    • limited character set
    • this isn't the 1960s

    Note: ASCII is 7-bit, not "extended" and not to be confused with Windows-1252, ISO 8859-1, or anything else.

提交回复
热议问题