[Tutor] Comments appreciated

jasonchild at cnsp.com jasonchild at cnsp.com
Mon Dec 27 15:50:06 CET 2004

[edited for sanity]

> An advantage here is that this guess() function is less tied to outside
> global resources, and is, in theory, more easily reused.  If we wanted to
> rewrite the program so that we take three different passwords, the version
> without global variables is easy to write:
>     guess("elbereth")
>     guess("open sesame")
>     guess("42")
> But the one with the global variable use is something much uglier on our
> hands:
>     password = "elbereth"
>     guess()
>     password = "open sesame"
>     guess()
>     password = "42"
>     guess()
> Anyway, sorry about the confusion.  I have to read threads more carefully!

indeed. I recently wresteled with the pros and cons of global variables.
What I did was to create a class that stores (via access funcs) important
data for my application. Said data is populated at startup from a text
file. This allows me to pass a single object that contains loads of conf
data to the important init functions (which my, indeed, change the data
depending on various factors). Now, memory wise this may not be the best
thing to do. Another alternative I considered would be to pass a sequence
type (mapping, array, tupple, whatever) from func to func (where it is
needed that is). Needless to say that at this point I am not overtly
concerned with optimizing my script, as I actually have another script
that sorts my data sources every 4 hours or so (to keep from parsing HUGE
files at every user request the script sorts and saves seperate files for
each user).

More information about the Tutor mailing list