[Tutor] code structure terminology and advice

Che M pine508 at hotmail.com
Wed Jul 22 02:05:01 CEST 2009

Hi, this is really more of a general programming question than a Python question, though perhaps there is a Python-relevant set of terms/answers to it... I'm trying to refactor some code to be more structurally "proper", more easily maintained, etc.  Doing some "thinking out loud", and I have two questions:  

Q1) Generally, what is the best structure for when there are a number of steps/actions that need to be taken?  Q2) Is there a term/some jargon in programming that refers to the difference between examples 1-3 below?

Examples:  Let's say I have some wish to perform four related sequential actions--steps, let's call them--in some part of the program.  In terms of grouping those actions, there are 3 ways I can think to do this (pseudocode):

1. Do the steps all in one function:

def Function(self):
  do step1 action
  do step2 action
  do step3 action 
  do step4 action

2. Have each step be a function, and have each function call the next function in the chain:

def StepOne(self):

   do step1 action


def StepTwo(self):

   do step2 action


3. Make each step a function, but call all of them in order in one master function:

def MasterFunction(self):

(elsewhere these functions are defined)


It seems to me that example 3 is the most sensible.  1 is bad because the steps should be functions, because then they can be easily reused, seen from an IDE explorer, etc. (I guess if they are really minor things it isn't necessary). 2 is terrible because it introduces far too much dependence and might be hard to maintain.  It is also possible to sort of mix aspects of all of these...that also seems jumbled.

Maybe there are other and better ways to think about organizing a sequence of steps, and if so I'd love to hear them.  I'd also like to know what I might look up to read up on managing this kind of thing.


Windows Live™ Hotmail®: Search, add, and share the web’s latest sports videos. Check it out.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090721/f88ecb07/attachment.htm>

More information about the Tutor mailing list