quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sterling Hughes <sterl...@bumblebury.com>
Subject Re: PSP opinion?
Date Sat, 24 May 2003 02:26:34 GMT
On Fri, 2003-05-23 at 23:35, Gregory (Grisha) Trubetskoy wrote:
> [This might take 4 minutes or more to understand]
> 
> In my experimenting with the PSP scanner, I tried to improve it by
> converting text that spans multiple lines into a Python triple-quote
> string. (I haven't yet checked any of this code in, so you'll just have
> go by my description below).
> 
> To illustrate, *before*:
> 
> <html>
> Hello World
> </html>
> 
> Would result in:
> 
> req.write("<html>")
> req.write("Hello world")
> req.write("</html>")
> 
> But the *new* way would result in:
> 
> req.write("""<html>
> Hello world
> </html>""")
> 
> The unintended consequense of this is that only the first indent after
> Python code terminator ("%>") matters, and the question is whether this is
> good or bad. At first it seemed good because you need to worry less about
> indenting, and there is no need for helpers like curly brackets.
> 
> But here is the unintuitive part:
> 
> <%
> for x in range(3):
> 	for y in range(3):
> %>
> 
> 		Inside Y loop line 1<br>
> 	Inside Y loop line 2<br>
> 
> The above converts into the following Python:
> 
> for x in range(3):
> 	for y in range(3):
> 
> 	        req.write("""Inside Y loop line 1<br>
> 	Inside Y loop line 2<br>
> """)
> 
> SO, even though line 2 is indented less, it is still going to be inside
> the "y" loop.
> 
> Here is a "solution" to this:
> 
> <%
> for x in range(3):
> 	for y in range(3):
> %>
> 
> 		Inside Y loop line 1<br>
> <%%>
> 	Inside X loop line 1<br>
> 
> 
> The "<%%>" above will end the string, so this will result in the following
> Python:
> 
> for x in range(3):
> 	for y in range(3):
> 
> 	        req.write("""Inside Y loop line 1<br>
> """)
> 	req.write("""Inside X loop line 1<br>
> """)
> 
> I'd appreciate some opinion on whether this way of doing this is
> preferred, or should we revert to the old behaviour of writing
> individually every line and therefore have every line's indent matter.
> 
> My take on it is - the "new" way is definitely going to be faster (i like
> that), because it's better to send one huge string than 100 small ones.
> The indent gotcha and the "<%%> workaround could just be something people
> would have to learn to live with. Or perhaps there could be an even
> cleverer way of reducing indent.

I don't think its a good idea to affect the syntax.  Any application
that is reasonably high performance should be buffering writes, so its
really just the function call overhead.  I don't see that being
incredibly inefficient.

Also, it should be possible to make the parser do block detection.  Ie,
translate:

<% for x in range(3): %>
	<% for y in range(3): %>
		Inside Y loop line 1
		Inside Y loop line 2
	Inside X loop line 1
	Inside X loop line 2

And have it become:

for x in range(3):
	for y in range(3):
		req.write("""			Inside Y loop line 1
		Inside Y loop line 2""")
	req.write("""		Inside X loop line 1
	Inside X loop line 2""")


-Sterling
-- 
"Programming today is a race between software engineers stirring to  
 build bigger and better idiot-proof programs, and the universe trying  
 to produce bigger and better idiots. So far, the universe is winning." 
    - Unknown


Mime
View raw message