[Python-ideas] An Alternate Suite Delineation Syntax For Python? (was Re: [Python-Dev] [PATCH] Adding braces to __future__)

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Dec 12 07:40:00 CET 2011


Mike Meyer wrote:

> Exactly. This change causes you to modify your architecture to deal
> with it.

It's not about "modifying" an architecture, it's about
considering the requirements and designing an appropriate
architecture from the beginning to accommodate them. If
you set out to generate Python code, write most of your
program and then say "Oh, bugger, what am I going to do
about indentation?", then you just haven't thought far
enough ahead.

Also, the particular architecture I suggested was only
an example. If you put your mind to it, you should be able
to come up with many ways of skinning this snake. If you
want to keep your generator style, you could yield special
"indent" and "dedent" tokens that the top level recognises
and does the appropriate thing with.

You might even use special strings such as "{:" and ":}"
embedded in the text to represent these. Then your code
generating methods wouldn't look all that much different
from how they would if you were generating the delimited
form of python that you are arguing for...

As a side note, I would argue that it's a good idea to
adopt an architecture that can manage indentation in any
case, whether you're generating indentation-sensitive code
or not.

I use this kind of architecture in Pyrex to generate C code,
even though indentation isn't required in C. I do it because
I want to generate properly-indented code anyway, for reasons
of readability. Even if the output is normally never seen,
it's a big help when debugging.

-- 
Greg



More information about the Python-ideas mailing list