Unification of Methods and Functions

Mark Hahn mark at prothon.org
Tue May 25 00:02:12 EDT 2004


Greg Ewing wrote:
> David MacQuigg wrote:
>> The load method is unique to Bags, and it belongs
>> in the Bag class.  To me this is a more fundamental consideration
>> than whether or not the method uses instance variables.
>
> Giving the function a name such as load_bag would be
> just as good in my opinion, if you don't want to dedicate
> a whole module to the Bag class.
>
> But then again, I don't see that dedicating a module
> to it would be such a bad thing, either.
>
> Python has what is termed a "package", which is
> a module containing other modules. You can use a
> package to group together modules which encapsulate
> related classes. If you have various collection
> classes, e.g., you might have a hierarchy of names
> like
>
>    collections.bags.Bag # class
>    collections.bags.load # function
>    collections.sets.Set
>    collections.sets.load
>
> etc.
>
> By the way, when I start writing a new Python program,
> often I'm tempted to put several classes in a module, only
> to regret it later as those classes grow and I end up
> with a huge source file that's hard to navigate around
> in. I'm coming to the view that it may be better to
> plan on one-class-per-module from the beginning.





More information about the Python-list mailing list