I can't find if PEP 8 talks about vertical distance of dependent functions (this is covered in the Clean Code book, Chapter 5: Formatting, section Vertical Formatting > Vertical Distance) and I want to know what the Python rules are for the order of function definitions.
After reading the Clean Code book, I'll create a class that defines the methods in the same order as they are used, like this:
class A:
def main(self):
self._function_1()
self._function_2()
self._function_3()
def _function_1(self):
print("Hi 1!")
def _function_2(self):
print("Hi 2!")
def _function_3(self):
print("Hi 3!")
But maybe PEP 8 specifies something different, because I see some scripts set the definition of the last used method first. They modify the above example as:
class A:
def main(self):
self._function_1()
self._function_2()
self._function_3()
def _function_3(self):
print("Hi 3!")
def _function_2(self):
print("Hi 2!")
def _function_1(self):
print("Hi 1!")
I've also heard that in Python the order of functions varies depending on whether they are in a class or not.
If you can give me information about it, I will be very grateful.
Thanks!
EDIT. A brief clarification, as shown in the examples in the question, I refer to vertical distance as how close the definition of a method is to its use, with no other method definitions in between.