Python modularity best practices

197 views Asked by At

I've been struggling conceptually with the design of my large program. The general layout is something like this:

def mainFunc(parm_1, parm_2, ..., parm_n):
  # do step 1
  # do step 2
  # ...
  # do step m

My question is this: Should I make each step its own function? I'd never want to call any step as a function outside of mainFunc. So, alternatively, would it be better to make each step a snippet? What's the practical difference between calling a function and executing a snippet which does the same thing? (Assuming of course that any unneeded variables are deleted at the end of the snippet.)

I truly don't know which approach is better in the long run. Any suggestions would be greatly appreciated.

1

There are 1 answers

0
Nogoseke On BEST ANSWER

If each step makes sense on its own, then it might be better to make functions. In that way you can document on each function what it does and it will also be easier to isolate bugs. In summary, I believe using functions makes the code easier maintain.