[Tutor] Q: Do Functions Have Any Class?

alan.gauld@bt.com alan.gauld@bt.com
Wed, 28 Mar 2001 12:47:52 +0100


> Besides their design and concept differences, is there really any
> (performance-based) reason to use classes/methods in a script 


OOP is all about two things - organisation and reuse.
If its simple the organisation may not be significant but 
being able to reuse things might be.

One major difference is elimination of global variables 
- and the implicit ability to have multiple instances.

Take a look at the Case Study in my online tutor. It shows 
this. The word counter as functions relies on global vas and 
this can only analyze one file at a time. By making a class 
we can have a counter per file...

But if you are writing a one-off very simple script 
just use functions...

There is no performance advantage in using classes unless 
you have a lot of different types and your code is full 
of if/elif constructs that call different functions 
depending on type. This will be faster using polymorphic 
classes. (Or dictionaries of function references - which 
is how the class does it :-)

Alan G