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

   self.StepTwo()



def StepTwo(self):

   do step2 action

   self.StepThree()


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

def MasterFunction(self):
  self.StepOne()
  self.StepTwo()
  self.StepThree()
  self.StepFour()

(elsewhere these functions are defined)

etc...


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.

Thanks,
Che

_________________________________________________________________
Windows Live™ Hotmail®: Search, add, and share the web’s latest sports videos. 
Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_videos_072009&cat=sports
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to