[Tutor] OT How to approach problem ?

Alan Gauld alan.gauld at blueyonder.co.uk
Sun May 23 18:27:02 EDT 2004

> Having written a program to track the ftse250, I have two large
lists of
> dictionaries forming 2 x 'fluid' matries. To access this data I have
> various defs which all use common pointers into the matries.

Probably twoi clases or maybe just two instances of one class
- since they are both lists of dictionaries they presumably
share common behaviour?

> OK this works, but apparently globals are to be avoided.

In principle yes, but...

> The only other way I can see is to define a class, and use
> instead of global pointers .... Since there would only be
> one instance of this class this seems a strange way to approach it.

One instance of a class is just hiding global variables. Might still
better because who knows when you find a need for multiple instances
(maybe even in another program 9in the future...). But generally a
single instance is just wallpaper over globals.

The other normal approach is to pass the pointers in as parameters of
the functions. This might mean a lot of parameters but intelligent
use of default values can often make it manageable and make the
functions much more reusable.


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list