Attack a sacred Python Cow

Michael Torrie torriem at gmail.com
Mon Jul 28 11:02:45 CEST 2008


Nikolaus Rath wrote:
> Thats true. But out of curiosity: why is changing the interpreter such
> a bad thing? (If we suppose for now that the change itself is a good
> idea).

Round and round and round we go.

Because by doing as you suggest you'd be altering the internal
consistency of how python deals with objects, particularly function
objects.  By keeping all functions as function objects, we're able to
provide a consistent view of things both to the programmer and the
interpreter.  If we break this consistency then we're saying, well this
is always a function, except in this case, and except in this case, when
it's dealt with specially.  This does not fit at all with python's
established mantras.

In python, "def" does only one thing: it creates a function object and
binds it to a name.  That's it!  Making what def does context-sensitive
seems pretty silly to me, and without any real benefit.  As said before,
adding attributes after the fact that are functions is a chore, because
those functions can't be unit tested, and can't be clearly read and
understood by other programmers.




More information about the Python-list mailing list