[Python-ideas] Should Python have user-defined constants?
mertz at gnosis.cx
Tue Nov 21 11:16:03 EST 2017
ISTM that using the already widely used convention of ALL_CAPS for
constants is plenty for linters to warn about rebinding names.
Python believes "we're all adults here" after all. So even though it's
worth *warning* users if BUFFER_LIMIT gets redefined, there can be reasons
between consenting adults for doing so when you know what you are doing.
It feels similar to the fact that I *can* call:
But the spelling suggests a strong recommendation to use a more public
API. Exact same story with redefining an implied constant.
On Tue, Nov 21, 2017 at 7:47 AM, Victor Stinner <victor.stinner at gmail.com>
> 2017-11-21 7:33 GMT+01:00 Saeed Baig <saeedbaig616 at icloud.com>:
> > Hey guys I am thinking of perhaps writing a PEP to introduce user-defined
> > constants to Python. Something along the lines of Swift’s “let” syntax
> > “let pi = 3.14”).
> If you want to work on a PEP, you will have to write a strong
> rationale for it :-)
> > Do you guys think it would be a good idea? Why or why not? Do you think
> > there’s a better way to do it? I’d like to know what others think about
> > idea before making any formal submission (I’ve already posted this same
> > question on python-list, but I just wanted to gauge opinion here too).
> Python has different kinds of namespaces: module globals, class
> attributes, function local variables, etc.
> The https://github.com/fijal/quill programming language looks like
> Python but makes module globals *mapping* "immutable": setattr(module,
> 'var', new_value). Only the mapping is immutable, a value can be
> mutable. I guess that the motivation here is to help the optimizer to
> emit more efficient code.
> See also previous attempts:
> "PEP 416 -- Add a frozendict builtin type"
> => my motivation was to develop a sandbox for Python
> "PEP 351 -- The freeze protocol"
> => I guess that the main motivation was to previous programming
> mistakes, misuse of an API
> The question is if you only want to have a technical solution to
> prevent modification of module globals, or if you would like to
> advertize that a variable is constant and use it somehow.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas