From: John Nagle on 16 May 2010 21:57 James Mills wrote: > The only place global variables are considered somewhat "acceptable" > are as constants in a module shared as a static value. Python really ought to have named constants. For one thing, it's fine to share constants across threads, while sharing globals is generally undesirable. Also, more compile-time arithmetic becomes possible. Python does have a few built-in named unassignable constants: "True", "None", "__debug__", etc. "Ellipsis" is supposed to be a constant, too, but in fact you can assign to it, at least through Python 3.1. I think there's some religious objection to constants in Python, but it predated threading. John Nagle
From: James Mills on 16 May 2010 23:34 On Mon, May 17, 2010 at 11:57 AM, John Nagle <nagle(a)animats.com> wrote: > Â For one thing, it's fine to share constants across threads, while > sharing globals is generally undesirable. Â Also, more compile-time > arithmetic becomes possible. > > Â Python does have a few built-in named unassignable constants: > "True", "None", "__debug__", etc. Â "Ellipsis" is supposed to be a > constant, too, but in fact you can assign to it, at least through Python > 3.1. > > Â I think there's some religious objection to constants in Python, but > it predated threading. To be honest, classes work just fine for defining constants. (Though in my own code I use ALL UPPER CASE variables as it the style). --James
From: Steven D'Aprano on 17 May 2010 00:24 On Mon, 17 May 2010 13:34:57 +1000, James Mills wrote: > On Mon, May 17, 2010 at 11:57 AM, John Nagle <nagle(a)animats.com> wrote: >> For one thing, it's fine to share constants across threads, while >> sharing globals is generally undesirable. Also, more compile-time >> arithmetic becomes possible. >> >> Python does have a few built-in named unassignable constants: >> "True", "None", "__debug__", etc. "Ellipsis" is supposed to be a >> constant, too, but in fact you can assign to it, at least through >> Python 3.1. >> >> I think there's some religious objection to constants in Python, but >> it predated threading. > > To be honest, classes work just fine for defining constants. (Though in > my own code I use ALL UPPER CASE variables as it the style). In what way are they constant? Can you not modify them and rebind them? -- Steven
From: Steven D'Aprano on 17 May 2010 00:29 On Sun, 16 May 2010 18:57:15 -0700, John Nagle wrote: > James Mills wrote: >> The only place global variables are considered somewhat "acceptable" >> are as constants in a module shared as a static value. > > Python really ought to have named constants. +1 Unfortunately, it will most likely require new syntax, and semantics. While the concept of a constant is pretty straightforward for immutable types like ints and strings, what about mutable types? And then there's the moratorium, so even if we had agreement on semantics and syntax, and a patch, it couldn't be deployed for a few years. -- Steven
From: James Mills on 17 May 2010 00:31 On Mon, May 17, 2010 at 2:24 PM, Steven D'Aprano <steven(a)remove.this.cybersource.com.au> wrote: > In what way are they constant? Can you not modify them and rebind them? It's just style/convention :) Much like _ to denote private variables and methods! --james
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Updating values in a dictionary Next: Qt and progressBar - how to update |