1

I'm working on a module for clustering algorithms, clustering.py.

I noticed several functions in the module only pertain to the mean shift algorithm, so I thought it might make sense to group them under a MeanShift class.

Right now, it looks something like this:

class MeanShift:

    def cluster(args):
        *code*

    def update_mean_position(args):
        *code*

The update_mean_position function is called only by the cluster function, so I'm wondering if it should begin with an underscore to show it is for internal use only.

Also, is it acceptable to organize these functions in a class, or should they just remain as top-level functions in the clustering module?

4

1 Answer 1

2

Also, is it acceptable to organize these functions in a class, or should they just remain as top-level functions in the clustering module?

The usual advice is use a class when you have common data, and common functions, if your MeanShift class is entirely 'static' it could be left at toplevel, but if it has state it should probably be a class.

Any organization that helps code clarity is good, even if that means you have a 'static' class that is organizing 'static' methods!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.