1

I have a data science codebase that contains several classes. Several of the methods in the classes rely upon various helper functions. These functions will just precede the class definitions in my module.

My question is, is it accepted practice to have these helper functions outside of a class? The benefit of this is that when I call these functions in the class, I can just refer to them by their name without any sort of prefix.

matsuo_basho
  • 211
  • 2
  • 8
  • 2
    Canonical SE Q&A for this kind of questions: [How would you know if you've written readable and easily maintainable code?](https://softwareengineering.stackexchange.com/questions/141005/how-would-you-know-if-youve-written-readable-and-easily-maintainable-code) – Doc Brown Aug 01 '21 at 18:08

1 Answers1

5

Python is a multi-paradigm language. You don't have to force your code into an object-oriented style. In fact, you shouldn't.

So if it feels more natural to keep the helper functions as free functions outside of the class, that's probably a perfectly acceptable design. It's also the kind of design I would generally prefer.

amon
  • 132,749
  • 27
  • 279
  • 375