I think Hans is more concerned with do-not-repeat-yourself than making
those internal strings constant (the solution proposed in the article
would only make things slower).

I would take a patch trying to collect strings in one place but
(myregex.py does this to some extent). Yet there is an advatange to
keep some string defined in the place where they are used. I like for
example sql.py, highlight.py, template.py, html.py, http.py
winservice.py to be as separated from the reset as possible.
globals.py, main.py, compileapp.py, widget.py, shell.py, admin.py
instead all interact a lot with each other.

Massimo

On Jun 5, 8:01 pm, JohnMc <maruadventu...@gmail.com> wrote:
> Hans,
>
> Python does not possess a constant as part of the syntax. So something
> like CONST is nothing but a variable in uppercase. One could define a
> hidden class that acts as an immutable once defined as this example
> shows --http://code.activestate.com/recipes/65207/.  In Python would
> in most cases  define a var  as part of the constructor and that var
> is only referenced in the associated methods. But it is all the
> programmers responsibility as to the handling of the var for the
> methods.
>
> JohnMc
>
> On Jun 5, 3:46 pm, Hans Donner <hans.don...@pobox.com> wrote:
>
> > what is it you do not understand? perhaps I can exaplin it better.
>
> > Examples of 'strings'
> > - in PasswordWidget (sqlhtml.py) there is the default display for a
> > password, in FORM.accepts this is also re-used
> > - In the top of sql.py, when loading the drivers 'Postgre' is used as
> > a key, while later it looks like it is referred to as 'Postgres'
>
> > On Fri, Jun 5, 2009 at 10:29 PM, mdipierro<mdipie...@cs.depaul.edu> wrote:
>
> > > I do not understand. I am sure it is because of lack of sleep and
> > > headache due to broken glasses (waiting for a replament).
>
> > > Massimo
>
> > > On Jun 5, 3:09 pm, Hans Donner <hans.don...@pobox.com> wrote:
> > >> could be my upbringing and my fat fingers/reliance on autocompletion,
> > >> but I see a lot of repetitive code and strings, eg
> > >> table_field = re.compile('[\w_]+\.[\w_]+') and 'keyname' etc.
>
> > >> like the table_field being present in multiple files, why not move
> > >> them to some shared globals and import from there?
>
> > >> any reason why frequently reused keynames are not provided as CONST?
> > >> Esp when used in different parts of web2py.
> > >> This might also prevent the 'Postgre' (missing s?) in sql.py
>
> > >> I've only been using python for a short time, so this might be the
> > >> python way to do it.
>
> > >> Hans
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to