Const and the Zen of the Pythonista

Warren Postma embed at geocities.com
Wed Feb 9 11:41:55 EST 2000


I had a Zen like breakthrough today. Or maybe not.

After making peace with tab-indent stuff last week, the next thing to do was
wonder where my old friend, the "const" keyword went.  The debate over
constants in this newsgroup showed a clear division of opinion, but I
couldn't see for sure why it was good to leave the feature out of the
language.

Today,  I realized the obvious.  All const does is make an already strictly
typed language (at compile time) even more strict (and yet, only at compile
time) by catching some errors that can be caught at compile time. That is
the way of all compiled languages, and "const" is a good thing to have.
However, since Python isn't compiled, nor statically typed, introducing the
"const" keyword would be incongruous, like wearing brown shoes with a
tuxedo.  You would be introducing a runtime check in every variable write
(is this variable const, if so fail) and lowering performance, to duplicate
at runtime something that C only checks at compile time anyways. Am I
finally getting it or have I merely become a language-lawyer overnight?

    Sigh no more, ladies, sigh no more,
    Men were deceivers ever,--
    One foot in sea and one on shore,
    To one thing constant never.

Much-ado-about-nothing'ly-yr's

    Warren







More information about the Python-list mailing list