Hi. Just to respond to some peoples’ points… Bernardo asked 'This would be "constant" as in Java constants right? Referential constants, so that if an object were mutable you would still be able to change its internal state.’ Um, I’m not entirely sure what you mean, since I’ve never used Java. But if it means what I think it means, I would be INCLINED to say no. If, for example, I saw code like this: x = [9, 5, 7, 1] let y = x y[0] = 42 print(y) … I would expect that code to raise an error, not print “[42, 5, 7, 1]”, since you’re trying to modify the “constant” y in place, which… well, would kind of go against the idea of y being a constant, I thought (unless I’m misunderstanding what you meant by “object", since everything in Python’s an object). However, I might change my opinion if I heard a good reason why Java-like constants would be better. Serhiy asked, in relation to constants, “To do what? What problem do you need to solve?”. No problem in particular, to be honest. I just thought they’d be nice since they’d increase confidence that my variables-intended-to-be-constants wouldn’t get reassigned, and just to increase readability/explicitness to other programmers.
On 21 Nov 2017, at 20:08, python-ideas-request@python.org wrote:
Send Python-ideas mailing list submissions to python-ideas@python.org
To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/python-ideas or, via email, send a message with subject or body 'help' to python-ideas-request@python.org
You can reach the person managing the list at python-ideas-owner@python.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-ideas digest..."
Today's Topics:
1. Re: Should Python have user-defined constants? (Steven D'Aprano) 2. Re: Should Python have user-defined constants? (St?fane Fermigier) 3. Re: Should Python have user-defined constants? (Bernardo Sulzbach) 4. Star assignment in iterator way? (Kirill Balunov) 5. Re: Star assignment in iterator way? (Serhiy Storchaka)
----------------------------------------------------------------------
Message: 1 Date: Tue, 21 Nov 2017 19:13:42 +1100 From: Steven D'Aprano
To: python-ideas@python.org Subject: Re: [Python-ideas] Should Python have user-defined constants? Message-ID: <20171121081342.GK19802@ando.pearwood.info> Content-Type: text/plain; charset=us-ascii 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
------------------------------
Message: 2 Date: Tue, 21 Nov 2017 09:26:17 +0100 From: St?fane Fermigier
To: Python-Ideas Subject: Re: [Python-ideas] Should Python have user-defined constants? Message-ID: Content-Type: text/plain; charset="utf-8" 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
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@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 ?ghting the existing reality. To change something, build a new model that makes the existing model obsolete.? ? R. Buckminster Fuller