Automated code generation

M

Max M

Yesterday there was an article on Slashdot:
http://books.slashdot.org/article.pl?sid=03/09/04/1415210&mode=flat&tid=108&tid=126&tid=156

It is about automatic code generation.

I got interrested in the subject, did a web search, and it seems kind of
powerfull.

My main interrest is web development in Zope/CMF/Plone, where there is a
lot of repeated code in the products. So automated code generation seems
like a natural fit.

But every time I think of a use case, I immediately think of a way to do
it with encapsulation instead.

Does anybody have any experience using Python and automated code
generation where it actually make sense?

Or os it useless in a language as dynamic as Python?


regards max M
 
J

John Roth

Max M said:
Yesterday there was an article on Slashdot:
http://books.slashdot.org/article.pl?sid=03/09/04/1415210&mode=flat&tid=108&tid=126&tid=156

It is about automatic code generation.

I got interrested in the subject, did a web search, and it seems kind of
powerfull.

My main interrest is web development in Zope/CMF/Plone, where there is a
lot of repeated code in the products. So automated code generation seems
like a natural fit.

But every time I think of a use case, I immediately think of a way to do
it with encapsulation instead.

Does anybody have any experience using Python and automated code
generation where it actually make sense?

Or os it useless in a language as dynamic as Python?

There are a few places where automated code generation makes sense,
but these are mostly trivial time savers. For example, the propery()
function
could be extended to automatically generate trivial getters, setters and
deleters, saving some coding and making things clearer in the majority
of cases.

John Roth
 
E

Eddie Corns

Max M said:
It is about automatic code generation.
I got interrested in the subject, did a web search, and it seems kind of
powerfull.
My main interrest is web development in Zope/CMF/Plone, where there is a
lot of repeated code in the products. So automated code generation seems
like a natural fit.
But every time I think of a use case, I immediately think of a way to do
it with encapsulation instead.
Does anybody have any experience using Python and automated code
generation where it actually make sense?
Or os it useless in a language as dynamic as Python?

The target language doesn't have to be the same as the implementation
language. A short while ago I created a small code generation program that
created snippets of C code which were woven into a hand optimised C program.
The result was an extremely fast program (which it needed to be) which still
seemed to have some capabilities of the HLL I used to create it (Scheme in
this case). I wouldn't even have attempted doing the analysis of the user
input in C but it was so trivial in Scheme I was able to add lots of extras.
It would have been a reasonable project in Python too. I did in fact use
Python as a front end to hide what was happening.

However I would suspect there would be a lot less scope for generating Python
code. Its dynamic and reflexive nature make it unnecessary.

Eddie
 
C

Cameron Laird

Isn't SWIG a code generator?


Al

I'm regarding SWIG as not about writing in Python; it's
about writing in a combination of Python and C (or C++,
or Fortran, or ...).
 
E

Eugene Pervago

Isn't SWIG a code generator?

Most of what it generates is C++, Python is special in that there is
some optional wrapper code generated to use Python 2.2's features like
properties. No code, for example, is generated for Ruby (or Perl
AFAIK).

Eugene Pervago
Kahakai (Python scripted window manager) http://kahakai.sf.net/
 
S

Simon Burton

My classes often have a __str__/__repr__ that generates a
bit of python code that when eval'd will reproduce (a clone of) the instance.

Simon.

On Fri, 05 Sep 2003 18:30:19 +0200, Max M wrote:

....
 
D

darrell

I write tools for testing embedded systems.
They parse the .h files and doc files to associate names with hex
values... This produces meg's of .py files which then support writing
tools and test scripts.

Everything from structure layout to:

EMERGENCY_STOP_CMD=0x1234567L
....
SOME_STRUCT=(["f1","f2","f3"],">fI10s")
....
ERROR_100="Somethig bad"


Does this qualify as code generation?

When the project wants to change something like how we "log".
Python is used to parse the entire source tree making changes.
Not Python code generation but it's more complicated than
search/replace. And could be applied to a Python code base as well

Is this code generation?

--Darrell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top