On Thu, May 27, 2021 at 07:13:56PM -0700, Brendan Barnwell wrote: > On 2021-05-27 14:33, Steven D'Aprano wrote: > >But even if we did have actual constants, how does that help get static > >*variables*, you know, things that aren't constant but can vary? > > All of those use cases can already be handled with a class that > stores its data in an attribute.
And with one sentence you have just explained why Python doesn't have closures or generators. There is nothing that they do that can't be handled by a class. Oh wait, Python does have closures (since version 1.5) and generators (since 2.2). Maybe your argument "just use a class" isn't quite as convincing as you hoped. https://pyvideo.org/pycon-us-2012/stop-writing-classes.html (I actually love classes. I just don't think that every function should be a class.) We're not using Java. We have first class (pun intended) functions, and they are, perhaps, even more important than classes. They're certainly easier to right and more efficient for many purposes. Instead of writing a minimal bundle of * a class * with an init method * and a call method * and then create an instance this proposal will allow us to encapsulate that in a single function, just as closures and generators do. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/E7A5G62LWHOMSYSQSLSCC62J4KBOS3V3/ Code of Conduct: http://python.org/psf/codeofconduct/