autocoding project proposal

brianr at liffe.com brianr at liffe.com
Wed Jan 30 09:03:44 EST 2002


"Neil Hodgson" <nhodgson at bigpond.net.au> writes:

> Brian Raven:
> 
> > Can anyone suggest any problems with this approach, or was this what a
> > previous poster meant by being not that hard?
> 
>     Generating Python is really no different from other languages here. When
> automatically generating C/C++ code it is best to indent correctly to make
> the code readable. Just maintain a current indent level and add to it for
> ':' and subtract from it when ending a block.

I agree that it is desirable that generated code is human readable, even
if the probability of a human reading it is low. However, maintaining
the appropriate indent when generating code is not necessarily as simple
as you suggest.

For example, if you need to generate code fragments to replace tags in
an existing template (possibly read from a file), you would need to
parse the existing code to establish the appropriate indent.

This is simple in languages like C/C++ where you don't need to bother
with indentation when generating the code. As long as you put line
breaks in the right place, indentation can be taken care of by existing
applications (e.g. indent or emacs).

This is not the case for Python, unless you use something like pyindent
(is there anything else?), and you must help it by generating end of
block markers.

-- 
Brian Raven
Anyway, there's plenty of room for doubt.  It might seem easy enough,
but computer language design is just like a stroll in the park.

Jurassic Park, that is.



More information about the Python-list mailing list