User: Password:
Subscribe / Log in / New account

Re: Make Python code read-only

From:  Nick Coghlan <>
To:  "Steven D'Aprano" <steve-iDnA/YwAAsAk+I/>
Subject:  Re: Make Python code read-only
Date:  Wed, 21 May 2014 19:43:05 +1000
Message-ID:  <>
Archive-link:  Article

On 21 May 2014 11:48, "Steven D'Aprano" <steve-iDnA/YwAAsAk+I/> wrote:
> On Wed, May 21, 2014 at 03:37:42AM +1000, Chris Angelico wrote:
> > With that (rather big, and yet quite trivial) caveat, though: Looks
> > interesting. Optimizing for the >99% of code that doesn't do weird
> > things makes very good sense, just as long as the <1% can be catered
> > for.
> "99% of Python code doesn't do weird things..."
> It seems to me that this is a myth, or at least unjustifiable by the
> facts as we have seen it. Victor's experiment shows 25 modules from the
> standard library are modifiable, with 139 read-only. That's more like
> 15% than 1% "weird".

It also misses the big reason I am a Python programmer rather than a Java

For me, Python is primarily an orchestration language. It is the language
for the code that is telling everything else what to do. If my Python code
is an overall performance bottleneck, then "Huzzah!", as it means I have
finally engineered all the other structural bottlenecks out of the system.

For this use case, monkey patching is not an incidental feature to be
tolerated merely for backwards compatibility reasons: it is a key
capability that makes Python an ideal language for me, as it takes ultimate
control of what dependencies do away from the original author and places it
in my hands as the system integrator. This is a dangerous power, not to be
used lightly, but it also grants me the ability to work around critical
bugs in dependencies at run time, rather than having to fork and patch the
source the way Java developers tend to do.

Victor's proposal is to make Python more complicated and a worse
orchestration language, for the sake of making it a better applications
programming language. In isolation, it might be possible to make that case,
but in the presence of PyPy for a full dynamically optimised runtime and
tools like Cython and Numba for selective optimisation within CPython, no.

Python-ideas mailing list
Code of Conduct:

(Log in to post comments)

Copyright © 2014, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds