Class vrs. function

david_ullrich at my-deja.com david_ullrich at my-deja.com
Sun Jul 2 13:55:38 EDT 2000


In article <395E2425.8F6F8757 at uniserve.com>,
  Bob van der Poel <bvdpoel at uniserve.com> wrote:
>
> I see sample code for python/tkinter which looks like this:
>
> 	class main:
> 		def __init__(self):
> 			...do a bunch of init stuff
>
> 	a=main()
> 	root.mainloop()
>
> What I'm wonder is why the use of a class for this.

   You say it's "sample code". One possibility is that
sample code is not supposed to do what it does in the
best possible way, it's supposed to do what it does in
the most _illustrative_ possible way - it's supposed to
be a sample of how to do things in other situations
where the class will have more interesting methods.

   (Another possibility is that you overlooked the fact
that the class in question derives from another class,
so it actually does include more than just __init__,
you just don't see it on that page.)

DU

> Wouldn't it be
> just
> as clear and perhaps more efficient to do
>
> 	...do init stuff
> 	root.mainloop()
>
> Is this just a good habit being developed by those who think that
> classes are better than functions, or god forbid, inline code?
>
> While I'd asking, are there any penalties in the speed/memory usage
> departments on using classes vrs. functions?
>
> In case this isn't obvious I'm an old programmer who figured that C
was
> a really nice, almost-cross-platform assembly language....
>
> --
>    __
>   /  )      /         Bob van der Poel
>  /--<  ____/__        bvdpoel at uniserve.com
> /___/_(_) /_)         http://users.uniserve.com/~bvdpoel
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list