Question: Python modularity best practices


Python modularity best practices

Answers 1
Added at 2016-12-22 14:12

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.

Answers to

Python modularity best practices

nr: #1 dodano: 2016-12-22 14:12

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.

Source Show
◀ Wstecz