[swift-evolution] Prohibit invisible characters in identifier names

Magnus Ahltorp map at kth.se
Sat Jun 25 05:36:35 CDT 2016


> 25 June 2016 06:13 Charlie Monroe <charlie at charliemonroe.net> wrote:
> 
>> 
>> On Jun 25, 2016, at 12:21 AM, Magnus Ahltorp <map at kth.se> wrote:
>> 
>> As far as I can see, forcing the programmer to write identifiers in an only-ASCII language, and requiring that identifier names have to be meaningful to the programmer means that the programmer has to know a language that is written in only ASCII. Most people are not, and requiring that they first learn for example English to be able to write programs is absurd.
> 
> You can always write your identifier using ASCII. For languages that use the latin script, just extended with various accents, can be written without them (this is how I was taught). Any language I'm aware of can be eventually written in the latin script (Chinese, cyrilic, ...). 

Take this small example from the Swift book:

let favoriteSnacks = [
    "Alice": "Chips",
    "Bob": "Licorice",
    "Eve": "Pretzels",
]

func buyFavoriteSnack(person: String, vendingMachine: VendingMachine) throws {
    let snackName = favoriteSnacks[person] ?? "Candy Bar"
    try vendingMachine.vend(itemNamed: snackName)
}

Imagine being forced to write all your identifiers in Chinese script, based on the Mandarin transliteration of the English pronunciation:

假设 费弗勒特斯纳克斯 = [
    "Alice": "Chips",
    "Bob": "Licorice",
    "Eve": "Pretzels",
]

函数 拜费弗勒特斯纳克(珀尔瑟恩: 字符串, 文丁默欣: 文丁默欣) 会投掷 {
    假设 斯纳克内姆 = 费弗勒特斯纳克斯[珀尔瑟恩] ?? "Candy Bar"
    尝试 文丁默欣.文德(艾德姆内姆德: 斯纳克内姆)
}

At least you can write the strings in your familiar script. Since you probably don't know Chinese, it is best illustrated by converting it to (non-accented) Pinyin.

jiashe feifuletesinakesi = [
    "Alice": "Chips",
    "Bob": "Licorice",
    "Eve": "Pretzels",
]

hanshu baifeifuletesinake(poerseen: zifuchuan, wendingmoxin: wendingmoxin) huitouzhi {
    jiashe sinakeneimu = feifuletesinakesi[poerseen] ?? "Candy Bar"
    changshi wendingmoxin.wende(aidemuneimude: sinakeneimu)
}

You would probably quickly learn words like jiashe and hanshu, but every identifier else is actually still in English, just horribly garbled.

Please excuse any errors in the transliterations, but you would probably make some errors if you would have to write your code in Chinese as well.

> BTW how far along with programming do you think you'd get without the knowledge of English? All libraries, SDKs use English identifiers. The documentation is in English. For one to lear programming without actually knowing any English would require the language to have localizable identifiers. Can you imagine those? Given how much time is put here to standardize the naming of a few methods in the standard library, how would it look in other languages? 

There are actually programming resources in other languages than English. This is especially true for Chinese.

/Magnus



More information about the swift-evolution mailing list