dimanche 22 janvier 2023

How to structure public and private methods in python

Suppose I have a class with several public methods and several _private or "helper" method.

There is the problem of how to sort them in the code. It could be 1. all public then all private or 2. the private functions after the calling public functions. (See Best practice: ordering of public/protected/private within the class definition?

An alternative approach is nesting private functions but that has a runtime overhead.

How could be the code structured in order to easily peek:

  • The interface of the class
  • The logic structure of the functions?

Aucun commentaire:

Enregistrer un commentaire