Re: Style for modules with lots of constants

2006-11-02 Thread Scott David Daniels
Paul McGuire wrote: > class Constants(object): > pass > > Then I defined the context for my LEFT and RIGHT constants, which are being > created to specify operator associativity, and then my constant fields as > attributes of that object: > > opAssoc = Constants(object) > opAssoc.RIGHT = 0

Re: Style for modules with lots of constants

2006-11-02 Thread Neil Cerutti
On 2006-11-01, Paddy <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> The Glk API (which I'm implementing in native Python code) >> defines 120 or so constants that users must use. The constants >> already have fairly long names, e.g., gestalt_Version, >> evtype_Timer, keycode_PageDown. >> >> Ca

Re: Style for modules with lots of constants

2006-11-01 Thread bearophileHUGS
Ron Adam: > The disadvantage is an invalid flag may pass silently unless you do some sort > of > validation which may slow things down a bit. That string validation is usually necessary. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Style for modules with lots of constants

2006-11-01 Thread Ron Adam
Neil Cerutti wrote: > On 2006-11-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> Neil Cerutti: >>> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode', >>>'WriteAppend', 0) >> That "+" sign seems useless. A space looks enough to me. The >> functions can accept case-agnostic strin

Re: Style for modules with lots of constants

2006-11-01 Thread Ben Finney
Neil Cerutti <[EMAIL PROTECTED]> writes: > Calls to Glk functions are thus ugly and tedious. > > scriptref = glk.fileref_create_by_prompt( > glk.fileusage_Transcript | glk.fileusage_TextMode, > glk.filemode_WriteAppend, 0) > > Please give me some good style advice for t

Re: Style for modules with lots of constants

2006-11-01 Thread Rob Williscroft
Tim Chase wrote in news:mailman.1617.1162412498.11739.python- [EMAIL PROTECTED] in comp.lang.python: >>> The reason I used instances instead of just the Constants >>> class was so that I could define a little more descriptive >>> context for the constants, >> >> Sorry I don't know what you mean h

Re: Style for modules with lots of constants

2006-11-01 Thread Paddy
Neil Cerutti wrote: > The Glk API (which I'm implementing in native Python code) > defines 120 or so constants that users must use. The constants > already have fairly long names, e.g., gestalt_Version, > evtype_Timer, keycode_PageDown. > > Calls to Glk functions are thus ugly and tedious. > >

Re: Style for modules with lots of constants

2006-11-01 Thread Tim Chase
>> The reason I used instances instead of just the Constants >> class was so that I could define a little more descriptive >> context for the constants, > > Sorry I don't know what you mean here, could I have an example It helps in the recognition if you have separation between something like

Re: Style for modules with lots of constants

2006-11-01 Thread Rob Williscroft
Paul McGuire wrote in news:[EMAIL PROTECTED] in comp.lang.python: >>> opAssoc = Constants(object) >>> opAssoc.RIGHT = 0 >>> opAssoc.LEFT = 1 >> This is nice, but you can cut down on some of the cruft: >> Constants.LEFT = 1 > One man's cruft is another man's clarity. :-) > The reason I used

Re: Style for modules with lots of constants

2006-11-01 Thread bearophileHUGS
Rob Williscroft: > This is nice, but you can cut down on some of the cruft: > > class Constants( object ): > pass > > Constants.RIGHT = 0 > Constants.LEFT = 1 > > ## client code ... > print Constants.LEFT Another possibility is to define such constants as strings instead of integers: _allflags

Re: Style for modules with lots of constants

2006-11-01 Thread Paul McGuire
"Rob Williscroft" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Paul McGuire wrote in news:[EMAIL PROTECTED] in > comp.lang.python: > >> >> class Constants(object) >> pass >> >> (I guess value immutability could probably be implemented using clever >> implementations of __seta

Re: Style for modules with lots of constants

2006-11-01 Thread Rob Williscroft
Paul McGuire wrote in news:[EMAIL PROTECTED] in comp.lang.python: > > class Constants(object) > pass > > (I guess value immutability could probably be implemented using clever > implementations of __setattr__ and such, but is it really worth the > bother?). > > Then I defined the context

Re: Style for modules with lots of constants

2006-11-01 Thread Neil Cerutti
On 2006-11-01, Paul McGuire <[EMAIL PROTECTED]> wrote: > I recently had to add some new constants to pyparsing, > representing LEFT and RIGHT, but I didn't want to define such > generic and likely-to-collide-with-user-code variable names. > > I settled on defining my own flavor of the Bag class, wh

Re: Style for modules with lots of constants

2006-11-01 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Errata: > opAssoc = Constants(object) Urk! Should be "opAssoc = Constants()" > and so on. In the client modules they would simply enter "from glk import > fileusage, filemode". Or if they just "import glk", the refere

Re: Style for modules with lots of constants

2006-11-01 Thread Neil Cerutti
On 2006-11-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Neil Cerutti: >> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode', >>'WriteAppend', 0) > > That "+" sign seems useless. A space looks enough to me. The > functions can accept case-agnostic strings and ignore spaces > in

Re: Style for modules with lots of constants

2006-11-01 Thread bearophileHUGS
Neil Cerutti: > scriptref = glk.fileref_create_by_prompt('Transcript+TextMode', >'WriteAppend', 0) That "+" sign seems useless. A space looks enough to me. The functions can accept case-agnostic strings and ignore spaces inside them. Example: ('transcript textmode ', 'writeappend', 0) > Pars

Re: Style for modules with lots of constants

2006-11-01 Thread Paul McGuire
"Neil Cerutti" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The Glk API (which I'm implementing in native Python code) > defines 120 or so constants that users must use. The constants > already have fairly long names, e.g., gestalt_Version, > evtype_Timer, keycode_PageDown. > > Ca