Class vrs. function

John W. Baxter jwbnews at scandaroon.com
Sat Jul 1 23:52:33 EDT 2000


In article <395EAF62.4A628573 at uniserve.com>, Bob van der Poel 
<bvdpoel at uniserve.com> wrote:

> Paul Prescod wrote:
> > 
> > Bob van der Poel wrote:
> > >
> > > ...
> > >
> > > Is this just a good habit being developed by those who think that
> > > classes are better than functions, or god forbid, inline code?
> > 
> > Given what you've said, that one-function class looks pretty bizarre. Is
> > there maybe something else useful about it that you haven't noticed?
> > Classes are not better than functions. They are just different. In most
> > cases, you use classes when you need to combine data and instructions.
> 
> Yes, that I understand. In some of the example code I've seen there is
> only the __init__ function and no data. That's why it doesn't make sense
> to me. Maybe I'm just having a bad day.....

Is there anything about those classes such that deriving from them would 
make sense?  If not, it's probably just a style issue (someone coming 
from SmallTalk--to pick one example--where there isn't any code outside 
some class might well do that).

Also, if the module is going to be imported, the code is handier if it 
isn't at the top level of the module:  import time may well not be the 
right time for the code to be run.  That wouldn't explain class vs 
function, though.

   --John

-- 
John W. Baxter   Port Ludlow, WA USA  jwbnews at scandaroon.com



More information about the Python-list mailing list