[Python-ideas] relaxing keyword usage restrictions

H Krishnan hetchkay at gmail.com
Fri Sep 9 08:04:28 CEST 2011


Hi,
I have read through the comments and the (largely negative) votes for this
idea.

The main argument against it seems to be readability. I feel the examples I
chose were distracting. The intent of the examples was to show the semantics
and not to suggest that anyone should write such code. One can write totally
unreadable code even with the current syntax:
if not was is can:
   return take
One cannot however write readable code such as the following:
if yield > principal:
   return = yield - principal

def send(from, to, message):
   ..

Syntax is something people will get used to. The following is perfectly
valid 'scheme' code:
(define define 3)
(* define 5)
In my 10+ years in scheme, I have never used 'define' as a symbol, nor have
I seen anyone else do it, even though there is no language restriction.
'self' is not a keyword in python, but I have not so far seen anyone use
'self' other than as the first argument of a class method.

The second argument was about the domino effect of such a change on parsing
and syntax highlighting tools. That is true for any change to the core
language, though the proposed change might cause more impact than most
others. If syntax highlighting tools can use python's ast and other modules
to identify keywords (instead of using their own parsers), the domino effect
will be lesser.

The use-case I had in mind was related to a customization tool we are
developing. We want to allow users to define expressions and assign them to
names. We 'eval' the expressions subsequently. We have to currently prevent
users from using any python keyword as a name, which I felt was an
unnecessary restriction.

I don't think a partial solution like allowing keywords as attributes will
work. It will be quite confusing and actually complicate the syntax
highlighters more than a full solution would.

Anyway, thanks for all the comments.

Regards,
Krishnan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110909/19d24c4a/attachment.html>


More information about the Python-ideas mailing list