[Baypiggies] Discussion for newbies/beginner night talks

Dennis Reinhardt DennisR at dair.com
Sat Feb 10 18:26:19 CET 2007


At 06:24 AM 2/10/2007, Aahz wrote:

>Strings like SQL and HTML that do not normally get presented to the user
>don't need to care about whitespace AT ALL.  Here's what I normally do at
>work:
>
>     sql = """
>         select c.name
>         from customers c
>         where c.activation_date > %s
>         """ % db.sql_repr(activation_date)
>
>The SQL itself may be further indented as needed for clarity


Sure, this works.  I would not put "AT ALL" in caps because that extra 
white space carries  extra runtime memory footprint and flows through CPU 
cache on string retrieval.  But, hey, if I were a total efficiency 
advocate, I would not be string appending or maybe even using Python.

For long strings with many substitutions, the line where the substitution 
is used (the %s) is many lines removed from where it is defined.  I think 
using and defining them on same line has better locality.  For the text 
body, this is very readable.

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



More information about the Baypiggies mailing list