Hello,

On Tue, 7 Jul 2020 17:22:28 +0100
Henk-Jaap Wagenaar <wagenaarhenkj...@gmail.com> wrote:

[]

> > >>      I don't like the .name syntax (grit on Tim's monitor; does

[]

> "PEP 622: Ditch leading dots for name loads": this is now an
> ex-syntax, it is bereft of life (for this, draft, of the PEP, might
> come back later!):
> https://github.com/python/peps/commit/f1de4f169d762cbb46fbfe94d2c01839db9b2f07
> 
> In there, it makes a good point that namespaced constants are good,
> especially for this kind of thing (you probably want to e.g. match
> over a bunch of possible constants which you can then put in an enum
> or some other namespace).

That's probably a nice move, but requiring constants to be
extra-namespaced seems like a pretty arbitrary and limiting "rule"
either.

This touches on the sentiment which I was too shy to share for a long
time even on python-ideas, but would like to take a chance to bring up
here now:

With the advent of Lua 5.4, Python appears to be **the only** of the
popular VHLL/scripting languages which doesn't support defining of
constants in the core language:

JavaScript has "const foo = 1;"
PHP has "const foo = 1;"
Perl has "use constant foo => 1;"
Lua has "local foo <const> = 1"


The closest Python has is:

---
from typing import Final
foo: Final = 1
--- 

which is done on the level of an arbitrary external module, and doesn't
enforce or employ const'ness on the language core level (unlike other
languages above).

If there were constants on the level of the core language, it would
*also* allow to elegantly resolve issue with the usage in match patterns
(in addition to baseline benefits of allowing programmers to express
programs more clearly and perform low-hanging optimizations). E.g.:

---
from __future__ import const

FOO: const = 1

match val:
    case FOO:  # obviously matches by constant's value
---


-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YPP2TWYONFL4BOR3MJHGTHWSPMQNP7J7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to