[Python-ideas] Make all keywords legal as an identifier

haael haael at interia.pl
Mon Apr 25 22:33:54 CEST 2011


@ Mike Graham

>> Of course, if a keyword is not preceded by a dot, it would be treated as a
>> reserved word, just like now.
>>> with = 3  # syntax error
> I don't see how this is a real improvement over the current
> convention, to add a trailing underscore, so that programs really
> needing to use the name "with" would use "with_". This does not
> introduce any new syntax and maintains the same level of backwards
> comparability your suggestion does.

But the trailing underscore is treated as a part of an identifier, while the 
preceding dot is not. This is important if I want to have an identifier named 
exactly "with", with no other characters (no pun itended).

As I said, I want sometimes to import some non-Python namespace, i.e. a Pascal 
program. If all identifiers are allowed, there would never be a clash of 
reserved words.



@ Terry Reedy

 > This very fact makes us *very* reluctant to add new keywords, which I think
 > is a pretty good thing.

So my change hits two birds with one stone: programmers could use any word as 
an identifier, developers could use any word as a token. Perfect solution.

 > as = 4 # syntax error

Read my proposal carefully. The module could access this name with a preceding dot:

 > .as = 4 # access to global and local variables



@ Sergio Surkamp

 > Why don't you use underscore instead of a dot?

As I said, the underscore is a part of a name, while the dot isn't.



@ Brain Curtin

 > Names tend to be nouns, so first I can't imagine why you'd want "with" as a
 > name, but you could exchange almost all keywords in the example and it's not
 > a great case. Making this change rather than working around poor name choice
 > gets a -1 from me.

First of all, many nouns are reserved, i.e. "object" or "class".

Second: variable names are usually nouns indeed, but functions and methods are 
often verbs, while named parameters can be prepositions and adverbs.

For example:
 > turtles.fight(with=honour)

Python kidnapped many verbs and prepositions and made them reserved.

However, no matter what we say, it's the programmer's choice which word to use. 
If he has a reason to use prepositions as variable names, it's none of our 
business.



Regards,
Bartosz Tarnowski



---------------------------------------------
Ksiegowa radzi: Jak załozyc firme w 15 minut?
http://linkint.pl/f2968




More information about the Python-ideas mailing list