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?

asked Jun 18, 2018 at 20:18
4
  • 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. Two underscores. Starting a function name with two underscores makes it private. Commented Jun 18, 2018 at 21:03
  • See also stackoverflow.com/q/10072204 Commented Jun 18, 2018 at 21:05
  • @RobertHarvey when would a single underscore be appropriate? I only want to indicate that it is for internal use, I don't need it to be fully private. This stackoverflow thread says that one underscore is a "weak internal use indicator". Commented Jun 18, 2018 at 21:51
  • Then I guess that's your answer. Commented Jun 18, 2018 at 22:12

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!

answered Jun 18, 2018 at 22:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.