[Tutor] Why difference between printing string & typing its object reference at the prompt?

Steven D'Aprano steve at pearwood.info
Thu Oct 11 03:44:03 CEST 2012


On 11/10/12 12:23, boB Stepp wrote:
> On Tue, Oct 9, 2012 at 4:29 AM, eryksun<eryksun at gmail.com>  wrote:
> <snip>
>> Python 3 lets you use any Unicode letter as an identifier, including
>> letter modifiers ("Lm") and number letters ("Nl"). For example:
>>
>>      >>>  aꘌꘌb = True
>>      >>>  aꘌꘌb
>>      True
>>
>>      >>>  Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ = range(1, 6)
>>      >>>  Ⅰ, Ⅱ, Ⅲ, Ⅳ, Ⅴ
>>      (1, 2, 3, 4, 5)
>
> Is doing this considered good programming practice?

Not really, but it depends who is doing it and why.

If you have a piece of code that is only going to be maintained by people
speaking French, with French keyboards, then why not use French words for
identifiers? That includes those French letters with accents. Python 3
lets you do so.

Silly bits of code like Ⅳ = 4 (or worse, Ⅳ = 9) should be avoided because
they are silly, not because they are illegal. That's about the same as
using:

eine, zwei, drei, vier, fünf = range(1, 6)

in code intended to be read by English speakers, only even harder to type.

Remember that programmers *discourage* most misspellings of words (with a
few exceptions, usually abbreviations):

number_of_pages = 42

is preferred to:

nombar_off_paiges = 42


But for non-English speakers, most languages *force* them to either
write code in Foreign (foreign *to them*), or to misspell words. Allowing
Unicode identifiers means that they can write in their native tongue,
using correct spelling, *if they so choose*.

Of course, if you want your code to be readable world-wide, stick to
English :)



-- 
Steven


More information about the Tutor mailing list