<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
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.&nbsp; Doing some "thinking out loud", and I have two questions:&nbsp; <br><br>Q1) Generally, what is the best structure for when there are a number of steps/actions that need to be taken?&nbsp; Q2) Is there a term/some jargon in programming that refers to the difference between examples 1-3 below?<br><br>Examples:&nbsp; Let's say I have some wish to perform four related sequential actions--steps, let's call them--in some part of the program.&nbsp; In terms of grouping those actions, there are 3 ways I can think to do this (pseudocode):<br><br>1. Do the steps all in one function:<br><br>def Function(self):<br>&nbsp; do step1 action<br>&nbsp; do step2 action<br>&nbsp; do step3 action <br>&nbsp; do step4 action<br><br>2. Have each step be a function, and have each function call the next function in the chain:<br>
<br>
def StepOne(self):<br>
&nbsp;&nbsp; do step1 action<br>
&nbsp;&nbsp; self.StepTwo()<br>
<br>
def StepTwo(self):<br>
&nbsp;&nbsp; do step2 action<br>
&nbsp;&nbsp; self.StepThree()<br>
<br>3. Make each step a function, but call all of them in order in one master function:<br><br>def MasterFunction(self):<br>&nbsp; self.StepOne()<br>&nbsp; self.StepTwo()<br>&nbsp; self.StepThree()<br>&nbsp; self.StepFour()<br><br>(elsewhere these functions are defined)<br><br>etc...<br>
<br>It seems to me that example 3 is the most sensible.&nbsp; 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.&nbsp; It is also possible to sort of mix aspects of all of these...that also seems jumbled.<br><br>Maybe there are other and better ways to think about organizing a sequence of steps, and if so I'd love to hear them.&nbsp; I'd also like to know what I might look up to read up on managing this kind of thing.<br><br>Thanks,<br>Che<br><br /><hr />Windows Live™ Hotmail®: Search, add, and share the web’s latest sports videos. <a href='http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_sports_videos_072009&cat=sports' target='_new'>Check it out.</a></body>
</html>