[Python-ideas] Should Python have user-defined constants?

Stéfane Fermigier sf at fermigier.com
Tue Nov 21 03:26:17 EST 2017


Javascript (ES6) has 'let' and 'const' for mutable and constant variables,
respectively.

When programming in JS, I find myself aggressively aiming for as little
'let' and as much 'const' as reasonably possible, since reasoning about
constants is much easier than about variables. In this context, 'const' is
used as a marker, a runtime checker, and, with proper tooling (IDE or
linter), a coding-time reminder to differentiate between these two
fundamental behaviours.

I'm not +1 on introducing this idea to Python yet, but not -1 either - this
deserves some discussion, if this has not been discussed already.

Cheers,

  S.

On Tue, Nov 21, 2017 at 9:13 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> On Tue, Nov 21, 2017 at 02:38:45AM -0500, Joseph Jevnik wrote:
>
> > How is that different from "pi = 3.14"?
>
> pi = 3.14
> pi = 5
> print(pi)
> # prints 5
>
> let pi = 3.14
> pi = 5
> # raises an exception
>
>
>
> --
> Steve
> _______________________________________________
> 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/
>



-- 
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -
http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software -
http://www.abilian.com/
Chairman, Free&OSS Group / Systematic Cluster -
http://www.gt-logiciel-libre.org/
Co-Chairman, National Council for Free & Open Source Software (CNLL) -
http://cnll.fr/
Founder & Organiser, PyData Paris - http://pydata.fr/
---
“You never change things by fighting the existing reality. To change
something, build a new model that makes the existing model obsolete.” — R.
Buckminster Fuller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/b26ce033/attachment.html>


More information about the Python-ideas mailing list