good design & method calls

Ron_Adam radam2 at
Tue Mar 29 20:32:57 CEST 2005

On Tue, 29 Mar 2005 09:09:37 -0500, Charles Hartman
<charles.hartman at> wrote:

>I know the answer to this is going to be "It depends . . .", but I want 
>to get my mind right. In Fowler's *Refactoring* I read: "Older 
>languages carried an overhead in subroutine calls, which deterred 
>people from small methods" (followed by the basic "Extract Method" 
>advice). In Skip Montanaro's "Python Performance Tips" 
>( I read: ". . .  
>use local variables wherever possible. If the above loop is cast as a 
>function, append and upper become local variables. Python accesses 
>local variables much more efficiently than global variables."
>These two pieces of advice imply opposite kinds of code revisions. 
>Obviously they have different purposes, and both are right at different 
>times. I wonder if anyone has some wisdom about how to think about when 
>or how often to do which, how to balance them ultimately, and so on.
>Charles Hartman
>Professor of English, Poet in Residence
>the Scandroid is at:

It depends... ;)

Converting small functions to inline, usually should  only be done in
the inner most loops to optimize performance if it's needed.  Moving
calculations out of those loops by doing them ahead of time is also

It's good practice in python to put all of your code in functions or
class's even if it's a single main() function.  

def main()
  (program code)


Then you avoid the slower globals unless you declare them with the
global statement.

If main, or any other functions, get too big or complex, split them up
as needed. 


More information about the Python-list mailing list