[Baypiggies] Discussion for newbies/beginner night talks

Dennis Reinhardt DennisR at dair.com
Sat Feb 10 00:40:00 CET 2007


>2) If you need to do a lot of string appends, use lists and join().

This is an optimization and as such may not be the first approach to 
consider.  All of the code samples I showed used string appends such as

        str  = ""
         str += "string 1"
         str +  "string 2"
        ...
Why?  ... because it is more concise and renders the code easier to 
read.  I think in 4 or so years, I have had to convert an append string 
such as this into appending list elements followed by a join once, maybe 
twice.

Your experience may differ but there is a clarity vs. efficiency tradeoff 
here and my experience is that the efficiency is rarely needed.

I realize Chad said "a lot".  That is a key qualifier.  When doing "a lot", 
efficiency matters.

>3) Understand and use iterators in loops.

I am using 2.3 and get by without iterators.  I would re-purpose this 
entirely.

Coming from other languages, the natural tendency is to iterate over a 
structure by index:

         for i in range(0,99):
            element = array[i]
             ...

The range operator is considered evil in that it builds a list at 
runtime.  So, taken literally, the advice could be construed to use an 
interator instead.

My advice is to not do either of the above.  Instead, iterate over the 
structure and let the array element be the loop iteration value.  Instead 
of iterators, do:

         for element in array:
             ...

and dispense with indicies to the extent that you can.  There will be cases 
where you need an index (e.g. updating element) but the first approach 
ought to be iterating over the structure.

>5) Understand and use the decorate/sort/undecorate (DSU) idiom.

I don't even know what that is.  When is the tutorial...?

Regards, Dennis


  ---------------------------------
| Dennis    | DennisR at dair.com    |
| Reinhardt | http://www.dair.com |
  ---------------------------------



More information about the Baypiggies mailing list