Could Quickstart's code generation system (or a code generation system
for crud forms) be written as a set of Kid templates? 

Didn't Ian just submit an enhancement to kid that enables text output,
which makes kid useful for generating any format of text file? 

Of course kid templates would need to generate other kid templates. Is
there a way of quoting for forcing the namespace, so a kid templates can
output xml in the same namespace? 

One good example of a successful and extremely useful code generation
system is SWIG:
http://www.swig.org

SWIG automatically generates wrappers for C and C++ interfaces, in many
different scripting (and general purpose programming) languages. It uses
an interface definition language that's an extension of C++ with
annotations that let you mark up your interfaces and specify calling
conventions, parameters handling, data type conversions, convenience
methods, etc. 

SWIG totally understands C++ data types, even C++ templates, and
supports an extensible, pattern based approach to mapping those
interfaces to many different scripting languages and extension APIs,
including raw xml metadata. 

SWIG takes an approach to code generation that requires you to declare
your extra stuff in an idl file (which looks like a .h file with extra
stuff [kinda like those double thick oreos]), so you never have to look
at or modify the generated code. 

The SWIG interface definitions can contain code snippets with variable
substitution, which are used for defining convenience methods, general
purpose parameters conversions, or scripting-language specific interface
adaptors. SWIG is largely written as a bunch of reusable template
libraries, a C++ data type pattern based template engine, into which
plugs a bunch of back-end code generators for the various languages it
supports. (The list of supported languages is quite impressive!) 

SWIG has a pattern based code generation system, with patterns based on
C++ data types and parameter names. It injects dynamically generated
code from templates into various places of the interface wrappers. 

For simple interfaces that you control, you can start with (or include)
a normal .h file, and use pattern based type conversion declarations to
customize the interface without inserting any annotations, so the C++
compiler can read the same header file as the interface generator, and
you Don't Repeat Yourself. 

But for more complex interfaces (or interfaces you don't control or
don't have headers for) you can wrap them by writing your own separate
interface definitions in the SWIG superset of C++ syntax, simplify them
by omitting unnecessary properties and methods, and extend them by
adding helper methods to the wrappers to make more convenient and
powerful scripting interfaces. 

For a great example of how SWIG can wrap a complex set of interfaces,
check out the OpenCV open source computer vision library:
http://sourceforge.net/projects/opencvlibrary/
http://www.ient.rwth-aachen.de/team/asbach/opencv-python.html

There is a big difference between wrapping C++ interfaces and SQL
databases, but SWIG has dealt with many thorny code generation issues
that are common to both problems, so it's worth taking a good look at.
And of course it's actually extremely useful, not just cool to look at! 

        -Don


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
On Behalf Of william
Sent: Friday, November 04, 2005 12:57 PM
To: TurboGears
Subject: [TurboGears] Re: Interesting thoughts on code generation


Michele,

thanks, this is a good summary of my ideas.

Quickstart should be able to generate a kind of pseudo-code. If
re-generation are need, why not take advantage of the inheritance at
class level (or at object level like in Zope). But this can add lot of
complexity; I like simplicity ;-).

Personnally, I'll be very happy even if quickstart does only 80% of the
task. If this is well documented where are the 20% to make manually.

My dream is to have a Quickstart that build:
- standard class controlers with view, edit and save methods.
- very simple kid template that just displays data and forms.

It's a kind of CatWalk, but at the code level.

Concerning the impact of regeneration, I'm just thinking of Glade.
They've made something that clearly define (in the generated code)
where the developers can add his own code and where he cannot make
modifications.

William

Reply via email to