[Baypiggies] Discussion for newbies/beginner night talks - stan

Dennis Reinhardt DennisR at dair.com
Wed Feb 14 17:22:15 CET 2007


At 11:03 PM 2/13/2007, Drew Perttula wrote:

 >Some notes:
 >The python lists and tuples in the xml-creating code will simply
 >disappear in the output. T.p["foo", "bar"] renders to "<p>foobar</p>".

Hmmm... I thought the x[y] syntax was doing an element access on dict or 
list x to find element y.  If x is an function, then I am guessing that 
x[y] is shorthand for

	z = [y]
	x(z)

or something like that.

A snippet from Dennis:
 >>                  html += "<td><a href=edt_main.py?slct=edit"
 >>                  html +=     "&class=tree_open32"
 >>                  html +=     "&index=%s"       % keye
 >>                  html +=     "&act=%s"         % act
 >>                  html +=     "><%s></a></td>" % hovered_img(ht_obj, index)

The equivalent snippet from Drew
 >                  cols = [T.td[T.a(href=("edt_main.py?slct=edit"
 >                                         "&class=tree_open32"
 >                                         "&index=", keye,
 >                                         "&act=", act)
 >                                   )[hovered_img(ht_obj, index)]],


I guess the nesting take some getting used to.  Stripping all the contained 
wording, Drew's version above becomes

	cols = [[(())[()]],

where the opening "[" is not balanced because it is closed later>  Compare 
the equivalent stripped version of Dennis's code

	html += "<td><a><%s></a></td>"

I think moving the nesting of html into Python "[...]" and "(...)" creates 
its own difficulties in reading and understanding.

 >Nevow gets quoting right, so probably some of the other code could be
 >simplified. hovered_img() should return a stan structure instead of the
 >insides of an img tag, too.

So some of the nesting in the stripped version above would simplify, 
right?  Maybe the stripped code becomes

	cols = [[(())],

???

 >My version of the code has 2/3 as many "words" as the original, as
 >counted by wc. Does that make it easier to maintain? I'm not sure,

Dennis's stripped version has 5 words while Drew's has 0.  Those extra 
words help to visually scan the html.  I think those extra words may be 
reducing cognitive load, allowing easier manual matchup of nesting.

Drew's version is moving some of the html nesting into Python.  I am not 
sure which version would be easier to maintain either.

 >http://cheeseshop.python.org/pypi/Breve/1.0.35
 >http://www.kieranholland.com/code/documentation/nevow-stan/

thanks for your version and the references.

regards, Dennis


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



More information about the Baypiggies mailing list