[Python-ideas] Should Python have user-defined constants?
David Mertz
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:
instance._Klass__secret()
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>
wrote:
> 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
> (e.g.
> > “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
> this
> > 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"
> https://www.python.org/dev/peps/pep-0416/
> => my motivation was to develop a sandbox for Python
>
> "PEP 351 -- The freeze protocol"
> https://www.python.org/dev/peps/pep-0351/
> => 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.
>
> Victor
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> 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...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/504742cf/attachment.html>
More information about the Python-ideas
mailing list