Python code/function layout
I am learning Python and am trying to figure out the best way to structure
my code.
Lets say I have a long function, and want to break it up into smaller
functions. In C, I would make it a 'static' function at the top level
(since that is the only level of functions). I would also probably forward
declare it and place it after the now-shortened function that uses it.
Now for Python. In Python, I have the option to create a nested function.
Since this new "inner" function is really only a piece of the larger
function broken off for readability purposes, and only used by it, it
sounds like it should be a nested function, but having this function
inside the parent function causes the whole function to still be very
long, since no code was actually moved out of it! And especially since the
functions have to be fully coded before they are called, it means the
actual short function is all the way down at the end of this pseudo-long
function, making readability terrible!
What is considered good practice for situations like this?
No comments:
Post a Comment