[Python-ideas] Make all keywords legal as an identifier
Masklinn
masklinn at masklinn.net
Mon Apr 25 22:21:07 CEST 2011
On 2011-04-25, at 22:13 , Brian Curtin wrote:
> On Mon, Apr 25, 2011 at 15:05, Mike Graham <mikegraham at gmail.com> wrote:
>> On Mon, Apr 25, 2011 at 3:51 PM, Brian Curtin <brian.curtin at gmail.com>
>> wrote:
>>> On Mon, Apr 25, 2011 at 14:36, haael <haael at interia.pl> wrote:
>>>>
>>>> Hello, guys.
>>>>
>>>> I did post this idea a few months ago. Now the revised version.
>>>>
>>>>
>>>> Goal:
>>>> Let _all_ alphanumeric keywords be legal as names for variables,
>> functions
>>>> and classes, even the ones that are reserved words now.
>>>>
>>>> Rationale:
>>>> 1. Python took most good English words as reserved tokens. Situation
>> goes
>>>> worse from version to version. I often have hard time searching for
>>>> acceptable synonyms.
>>>> 2. Because of that, old Python programs cease to work, even if they do
>> not
>>>> use any abandoned features. Their only sin is using certain words that
>>>> further versions of Python have stolen away.
>>>> 3. Sometimes one needs to import keywords from some other language, XML
>> be
>>>> an example, or "translate" another programming language into Python in
>> one
>>>> way or another. Keyword reservation is a big problem then; it does not
>> allow
>>>> to use the natural Python syntax.
>>>>
>>>> Solution:
>>>> Let the parser treat all keywords that come after a dot (".") as regular
>>>> identifiers.
>>>>
>>>>
>>>> For attributes, nothing changes:
>>>>> boo.for = 7
>>>>
>>>> For names that are not attributes, only one syntax change is needed: let
>> a
>>>> dot precede any identifier.
>>>>> .with = 3
>>>
>>> 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.
>>
>> To nitpick, names don't tend to be nouns only. Names of functions and
>> methods tend to be verbs and names of interfaces and abstract classes
>> are sometimes adjectives.
>
>
> The point still stands regardless of my your nitpicking. "with" is a bad
> name for any of those. As is try, raise, pass, import, break, True, etc.
With is actually a very nice name for some things, it creates very readable, english-looking code.
And what about `class`? Or `for` (that one clashes hard against the HTML object model, label elements have a for attribute). `in`, `except` or `is` may also be interesting in some cases.
Do all Python keywords have this issue? No, I doubt anybody's ever tried to called an attribute `elif`, but I definitely ran into the issue a few times.
More information about the Python-ideas
mailing list